Display expression value in Razor

泪湿孤枕 提交于 2019-12-23 18:29:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!