Html.RadioButtonFor MVC绑定

tri*_*thy 2 c# asp.net-mvc radio-button razor asp.net-mvc-4

我的视图有一个字符串属性.通过操作结果执行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);
}
Run Code Online (Sandbox Code Playgroud)

我的观点.cshtml

@Html.Label("tea:")
@Html.RadioButtonFor(m => m._teaOrCoffee, Model._teaOrCoffee)  
@Html.Label("coffe:")
@Html.RadioButtonFor(m => m._teaOrCoffee, Model._teaOrCoffee) 
Run Code Online (Sandbox Code Playgroud)

模型

public string _teaOrCoffee {get; set;}
Run Code Online (Sandbox Code Playgroud)

如何绑定值,@Html.RadioButtonFor以便在加载时它应显示为选中状态?

gra*_*nit 8

使用第二个参数@Html.RadioButtonFor()设置应选择的值.

@Html.RadioButtonFor(model => model._teaOrCoffee, "T") @Html.Label("tea:")
@Html.RadioButtonFor(model => model._teaOrCoffee, "C") @Html.Label("coffe:")
Run Code Online (Sandbox Code Playgroud)