在Razor中显示表达式值 [英] Display expression value in Razor

查看:85
本文介绍了在Razor中显示表达式值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在剃刀视图中将以下表达式的值显示为文本.

I want to display the value of the below expression as a text in razor view.

@(doc.Extension ?? string.Empty).ToUpperInvariant(); 

我尝试了所有变体,但似乎无济于事. 我知道我可以使用temp变量来存储此表达式的值,但是我想知道是否有一种方法可以内联.

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();} 

推荐答案

如果不使用分号,Razor会将代码解释为表达式而不是语句.例如:

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())

这篇关于在Razor中显示表达式值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆