我的视图有一个字符串属性.通过操作结果执行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以便在加载时它应显示为选中状态?
我有两个操作结果,一个发送字符串,另一个加载视图
public ActionResult getTheString()
{
string message = //doing some thing ;
myModel myModel = new myModel();
myModel.property1 = message ;
return loadView(myModel);
}
public ActionResult loadView(myModel model)
{
return view (model);
}
Run Code Online (Sandbox Code Playgroud)
@model project.Models.myModel
@{
if(Model.property1 !=" ")
{what to do to show it as alert }
}
Run Code Online (Sandbox Code Playgroud)
在这里,我得到的好处是,model.property1是否有一些东西显示带有该字符串的警报,然后加载,如果消息中不包含任何内容,则只需加载即可。
不允许使用TempData,ViewBag,ViewData。
不允许在view中使用Script标签。它必须在单独的js文件中