如何在Razor中声明局部变量? [英] How to declare a local variable in Razor?
本文介绍了如何在Razor中声明局部变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在asp.net mvc 3中开发一个Web应用程序。
我对此很陌生。在使用剃刀的视图中,我想声明一些局部变量,并在整个页面中使用它。
I am developing a web application in asp.net mvc 3. I am very new to it. In a view using razor, I'd like to declare some local variables and use it across the entire page. How can this be done?
能够执行以下操作似乎很简单:
It seems rather trivial to be able to do the following action:
@bool isUserConnected = string.IsNullOrEmpty(Model.CreatorFullName);
@if (isUserConnected)
{ // meaning that the viewing user has not been saved
<div>
<div> click to join us </div>
<a id="login" href="javascript:void(0);" style="display: inline; ">join</a>
</div>
}
但这是行不通的。
推荐答案
我认为您距离很近,请尝试以下操作:
I think you were pretty close, try this:
@{bool isUserConnected = string.IsNullOrEmpty(Model.CreatorFullName);}
@if (isUserConnected)
{ // meaning that the viewing user has not been saved so continue
<div>
<div> click to join us </div>
<a id="login" href="javascript:void(0);" style="display: inline; ">join here</a>
</div>
}
这篇关于如何在Razor中声明局部变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文