asp.net-mvc-3 – 强类型的RadioButtonlist
发布时间:2020-05-23 15:00:31 所属栏目:asp.Net 来源:互联网
导读:我想要获得一些选项(例如付款方式现金,信用卡等),并将其绑定到单选按钮。我相信MVC 3中没有RadioButtonList。 另外,一旦收音机被绑定,我想在编辑答案时向用户显示先前选择的选项。 和往常一样,你从一个模型开始: public enum PaiementMethod{ Cash, Cre
|
我想要获得一些选项(例如付款方式现金,信用卡等),并将其绑定到单选按钮。我相信MVC 3中没有RadioButtonList。 另外,一旦收音机被绑定,我想在编辑答案时向用户显示先前选择的选项。 解决方法和往常一样,你从一个模型开始:public enum PaiementMethod
{
Cash,CreditCard,}
public class MyViewModel
{
public PaiementMethod PaiementMethod { get; set; }
}
那么一个控制器: public class HomeController : Controller
{
public ActionResult Index()
{
var model = new MyViewModel();
return View(model);
}
[HttpPost]
public ActionResult Index(MyViewModel model)
{
return View(model);
}
}
最后一个观点: @model MyViewModel
@using (Html.BeginForm())
{
<label for="paiement_cash">Cash</label>
@Html.RadioButtonFor(x => x.PaiementMethod,"Cash",new { id = "paiement_cash" })
<label for="paiement_cc">Credit card</label>
@Html.RadioButtonFor(x => x.PaiementMethod,"CreditCard",new { id = "paiement_cc" })
<input type="submit" value="OK" />
}
如果您想要一些更通用的解决方案,将其封装在帮助器中,您可能会发现following answer有帮助。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 执行迁移EF core 2.0时出错,将Identity id从string更改为in
- asp.net-mvc – 在实体框架中使用存储过程
- IIS ASP.Net网站 – ManagedPipelineHandler错误(尝试对不存
- 在asp.net应用程序中管理与数据库的连接
- ASP.Net MVC中长时间运行服务器调用的进度条
- asp.net-mvc – 如何创建文件并通过ASP.NET MVC中的FileRes
- Owin错误与ASP.NET MVC应用程序
- .NET图表控件 – 轴X文本旋转
- ASP.NET Core WebApi将错误消息返回给AngularJS $http prom
- 将列表绑定到asp.net 3.5中的列表视图
