我的视图有一个字符串属性。通过操作结果执行get请求并将其发送到视图--如下所示:
public ActionResult TeaCoffeView(string teaOrCoffee)
{
MyModel model = new MyModel();
//do some stuff
//teaOrCoffee has two values , if "T" i have
//to make the view as tea radio button selected
//or if it has "C" then coffee radio button selected
return View(model);
}我的视图.cshtml
@Html.Label("tea:")
@Html.RadioButtonFor(m => m._teaOrCoffee, Model._teaOrCoffee)
@Html.Label("coffe:")
@Html.RadioButtonFor(m => m._teaOrCoffee, Model._teaOrCoffee) 模型
public string _teaOrCoffee {get; set;}如何将值与@Html.RadioButtonFor绑定,以便在加载时将其显示为选中状态?
发布于 2017-04-18 21:05:33
使用@Html.RadioButtonFor()中的第二个参数来设置应该为其选择的值。
@Html.RadioButtonFor(model => model._teaOrCoffee, "T") @Html.Label("tea:")
@Html.RadioButtonFor(model => model._teaOrCoffee, "C") @Html.Label("coffe:")https://stackoverflow.com/questions/43472579
复制相似问题