如何申报剃刀局部变量 [英] how to declare local variable in Razor

查看:146
本文介绍了如何申报剃刀局部变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在开发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>
}

但是,这并不正常工作。这可能吗?

But this doesn't work. Is this possible?

推荐答案

我觉得你是pretty的接近,试试这个:

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
    <div>
        <div> click to join us </div>
        <a id="login" href="javascript:void(0);" style="display: inline; ">join</a>
    </div>
}

这篇关于如何申报剃刀局部变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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