2015-12-29 44 views
1

我有以下代碼@ Html.Label ASP.NET 4到ASP.NET 5

@foreach (var item in (SelectList)ViewBag.RoleId) 
{ 
    <input type="checkbox" name="SelectedRoles" value="@item.Value" class="checkbox-inline" /> 
    @Html.Label(item.Value, new { @class = "control-label" }) 
} 

,在ASP.NET工作4

然而,在ASP.NET 5沒有超載對於

@Html.Label(item.Value, new { @class = "control-label" }) 

結果的方法是,我得到一個編譯錯誤

問:

  1. 我必須使用普通的html還是有一種方法,我仍然可以使用HTML助手?

回答

0

您可以使用此重載

@Html.Label("Value","Value", new { @class = "control-label" }) 

還是Html.LabelFor helper方法

@Html.LabelFor(d => item.Value, new { @class = "control-label" }) 

@foreach (var item in (SelectList)ViewBag.RoleId) 
{ 
    <input type="checkbox" name="SelectedRoles" value="@item.Value" 
                 class="checkbox-inline"/> 

    @Html.Label("item.Value","Value", new { @class = "control-label" }) 
    <h2>Other option is </h2> 
    @Html.LabelFor(d => item.Value, new { @class = "control-label" }) 
} 

或者乾脆,你可以寫HTML標記(這是我個人的偏好)。

@foreach (var item in (SelectList)ViewBag.RoleId) 
{ 
    <input type="checkbox" name="SelectedRoles" value="@item.Value" 
                 class="checkbox-inline"/> 

    <label class="control-label" for="item_Value">Value</label> 
} 

在ASPNET5,團隊介紹,標籤傭工這將使我們寫的視圖的標記,而無需使用該@Html助手。這使得不瞭解C#的設計人員可以創建視圖標記。

0

ASP.NET 5中的@Html.Label只有IHtmlHelper.Label(string expression, string labelText, object htmlAttributes)接口。你可以看到源代碼aspnet/mvc

你可能需要將你的代碼改爲@Html.Label(item.Value, "Some text to display", new { @class = "control-label" })