2015-06-03 55 views
1

嗨我試圖在mvc基礎上運行視頻教程中的複選框字段,我看過https://www.youtube.com/watch?v=4KeoOPWshmw&list=PL6n9fhu94yhVm6S8I2xd6nYz2ZORd7X2v&index=38,我仔細地按照它。但有一個問題,複選框沒有顯示在我的瀏覽器中。不顯示覆選框在mvc

它只顯示文字12345和按鈕提交。

Index.cshtml

@model IEnumerable<MvcCheckBox.Models.City> 

@{ 
    ViewBag.Title = "Home"; 
} 

<h2>Index</h2> 
@using (Html.BeginForm()) 
{ 
    @Html.EditorForModel() 
    <br /> 
    <input type="submit" value="Submit" /> 
} 

City.cshtml

@model MvcCheckBox.Models.City 

@Html.HiddenFor(x => x.ID) 
@Html.HiddenFor(x => x.Name) 

@Html.CheckBoxFor(x => x.IsSelected) 
@Html.DisplayFor(x => x.Name) 
+0

是'City.cshtml'位於'/查看/共享/ EditorTemplates /'?也可以嘗試'@ Html.EditorFor(m => m)' –

+0

不,它位於/ Views/Home/EditorTemplates /中。 我也嘗試@ Html.EditorFor(m => m)但沒有任何變化.. 感謝您的回覆 – shinichi

+0

那麼'/ Views/Home /'中的'Index.cshtml'視圖? –

回答

0

通過觀看視頻,你可能錯過了這一步了:

右鍵單擊「EditorTemplates 「文件夾 - 添加 - 查看。在「添加 視圖」對話框中,設置視圖名稱=城市視圖引擎=剃鬚刀並單擊 「添加」。

然後複製你的代碼粘貼到它:

@{ ViewBag.Title = "City"; 
} 

@Html.HiddenFor(x => x.ID) 
@Html.HiddenFor(x => x.Name) 

@Html.CheckBoxFor(x => x.IsSelected) 

@Html.DisplayFor(x => x.Name)