下面的代码看起来不干净.有什么改进代码的建议吗?
<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>
Run Code Online (Sandbox Code Playgroud) 我的ViewModel中有一个名为DisableNextButton的布尔值,我想用它来禁用视图中的按钮。我应该补充一点,该按钮位于if语句内。
最终,我尝试在DisableNextButton为true时添加disabled属性。
这是我不成功的实现:
@if(true)
{
<button type="button" @{ if (Model.DisableNextButton) { <text>disabled="disabled"</text> } } >Next</button>
}
Run Code Online (Sandbox Code Playgroud)
我应该注意,这为我提供了一个功能已启用的按钮。