如何在ASP.Net视图中使用Html.RadioButtonFor? [英] How to use Html.RadioButtonFor in ASP.Net view?
本文介绍了如何在ASP.Net视图中使用Html.RadioButtonFor?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用带有C#语言的ASP.Net MVC。
我想编辑一个用户。用户表有一个名为IsActive的布尔字段。
在模型中,我使用的是ADO.Net实体数据模型。
public ActionResult Edit( int id){
var editUser =( from u in userEntity.USERs 其中 u.UserId == id 选择 u).First();
return 查看(editUser);
}
在视图中,Visual Studio for IsActive生成的脚本使用TextBox。
<% = Html.TextBoxFor(model => model.Activate)%>
In这种情况下,我想使用RadioButton代替选项是和否。
怎么做?
谢谢!
解决方案
<![CDATA [<%= Html.RadioButtonFor(model = > model.Active , true )%> ]] > 是
<![CDATA [<%= Html.RadioButtonFor(model = > model.Active, false )%> ]] > 否
尝试下面的...它应该可以工作。
model.Activate,true)%>]]>是
model.Activate,false)%>]]>否
I am using ASP.Net MVC with C# language.
I would like to edit a user. The user table has a boolean field called "IsActive".
In the model, I'm using ADO.Net Entity Data Model.
public ActionResult Edit(int id) {
var editUser = (from u in userEntity.USERs where u.UserId == id select u).First();
return View(editUser);
}
In the view, script generate by Visual Studio for IsActive is using TextBox.
<%= Html.TextBoxFor(model => model.Activate) %>
In this case, I would like to use RadioButton instead with the options Yes and No.
How to do it?
Thanks!
解决方案
<![CDATA[<%= Html.RadioButtonFor(model => model.Active, true) %>]]> Yes <![CDATA[<%= Html.RadioButtonFor(model => model.Active, false) %>]]> No
Try the below... It should work.
model.Activate, true) %>]]> Yes
model.Activate, false) %>]]> No
这篇关于如何在ASP.Net视图中使用Html.RadioButtonFor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文