Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline If in Razor View

In my controller, I have and inline If statement:

ViewBag.NameSortParam = If(String.IsNullOrEmpty(sortOrder), "Name desc", "")

In my view, I can't seem to use inline if:

@Code
    If(True, true, true)
End code

It says, "If must end with matching End If." Why can't I use an inline if here? Thanks.

like image 248
user1477388 Avatar asked Sep 12 '12 15:09

user1477388


3 Answers

You can do an inline if in vb.net like this:

@(If(testExpression, TruePart, FalsePart))
like image 182
shekky Avatar answered Oct 08 '22 21:10

shekky


Try

@Code
    @(If(True, true, true))
End Code
like image 29
Tim B James Avatar answered Oct 08 '22 22:10

Tim B James


You could use something like this:

   @(true? "yes": "no") 
like image 41
Big Daddy Avatar answered Oct 08 '22 21:10

Big Daddy