问题
I want to display the value of the below expression as a text in razor view.
@(doc.Extension ?? string.Empty).ToUpperInvariant();
I've tried every variant but nothing seems to work. I know i can use a temp variable to store the value of this expression but I was wondering if there was a way to do this inline.
@((doc.Extension ?? string.Empty).ToUpperInvariant();)
@{@:@(doc.Extension ?? string.Empty).ToUpperInvariant();}
回答1:
If you don't use a semicolon, Razor will interpret your code as an expression instead of a statement. E.g.:
@((doc.Extension ?? string.Empty).ToUpperInvariant())
来源:https://stackoverflow.com/questions/36051013/display-expression-value-in-razor