ASP.NET MVC剃须刀:在HTML条件属性 [英] ASP.NET MVC razor: conditional attribute in HTML
本文介绍了ASP.NET MVC剃须刀:在HTML条件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
code以下似乎并不干净。
任何建议提高code?
<李@if(计算机[页面名]的ToString()==业务范围){<文本>类=主动< /文本> }>
<一个@if(计算机[页面名]的ToString()==业务范围。){<文本>风格=颜色:白色,背景色:#08C;边界:1px的固体#08C; < /文字和GT; }
HREF =@ Url.Action(BusinessDetails,业务)>企业详细信息及LT; / A>
< /李>
<李@if(计算机[页面名]的ToString()==预订政策){<文字和GT;类=主动< /文字和GT; }>
<一个@if(计算机[页面名]的ToString()==预订政策)
{<文字和GT;风格=颜色:白色,背景色:#08C;边界:1px的固体#08C; < /文字和GT; }
HREF =@ Url.Action(BookingPolicies,业务)>的预订政策< / A>
< /李>
解决方案
MVC4测试版内置了...条件属性
< DIV @ {如果(MyClass的!= NULL){<文字和GT;类=@ MyClass的< /文字和GT; }}>内容< / DIV>
< DIV CLASS =@ MyClass的>内容< / DIV>
如果@myClass为null,它只是将不会使用属性在所有...
我知道,可能不太解决当前的问题,但值得注意的是!
<一个href=\"http://weblogs.asp.net/jgalloway/archive/2012/02/16/asp-net-4-beta-released.aspx\">http://weblogs.asp.net/jgalloway/archive/2012/02/16/asp-net-4-beta-released.aspx
Code below doesn't seems clean. Any suggestion to improve the code?
<li @if(ViewData["pagename"].ToString()=="Business details"){ <text>class="active" </text> } >
<a @if(ViewData["pagename"].ToString()=="Business details"){ <text>style="color: white; background-color: #08C; border: 1px solid #08C;" </text> }
href="@Url.Action("BusinessDetails", "Business")">Business Details</a>
</li>
<li @if (ViewData["pagename"].ToString() == "Booking policies"){ <text>class="active"</text> }>
<a @if (ViewData["pagename"].ToString() == "Booking policies")
{ <text>style="color: white; background-color: #08C; border: 1px solid #08C;" </text> }
href="@Url.Action("BookingPolicies", "Business")">Booking policies</a>
</li>
解决方案
MVC4 beta has conditional attributes built in...
<div @{if (myClass != null) { <text>class="@myClass"</text> } }>Content</div>
<div class="@myClass">Content</div>
If @myClass is null, it just won't use the attribute at all...
I know that may not quite solve your current issue, but it is noteworthy!
http://weblogs.asp.net/jgalloway/archive/2012/02/16/asp-net-4-beta-released.aspx
这篇关于ASP.NET MVC剃须刀:在HTML条件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文