我正在使用C#語言的ASP.Net MVC。 我想編輯一個用戶。用戶表具有名爲「IsActive」的布爾字段。 在模型中,我使用了ADO.Net實體數據模型。如何在ASP.Net視圖中使用Html.RadioButtonFor?
public ActionResult Edit(int id) {
var editUser = (from u in userEntity.USERs where u.UserId == id select u).First();
return View(editUser);
}
在視圖中,由Visual Studio for IsActive生成的腳本使用TextBox。
<%= Html.TextBoxFor(model => model.Activate) %>
在這種情況下,我想用單選按鈕,而不是用的選項是和 號怎麼辦呢? 謝謝!
感謝您的回覆! 但在這裏我想使用單選按鈕。怎麼樣? – 2012-02-13 01:44:12
當我使用它時,它顯示錯誤:CS0266:不能隱式轉換類型'bool?'到'布爾'。存在明確的轉換(您是否缺少演員?) – 2012-02-13 02:02:01
然後將其更改爲'model.IsActive.Value' - 它是'可空的'。這意味着數據庫中的'IsActive'字段允許'null',因此實體框架將該類型映射到'可爲空'' –
xandercoded
2012-02-13 02:03:19