我正在用 asp.net mvc 3 开发一个 Web 应用程序。我对它很陌生。在使用 razor 的视图中,我想声明一些局部变量并在整个页面中使用它。如何才能做到这一点?
能够执行以下操作似乎相当微不足道:
@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> }
但这不起作用。这可能吗?
我认为你很接近,试试这个:
@{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> }