问题描述
我是MVC的新手,我试图在视图页面中创建一个表单,该表单使我可以使用单选按钮选择数据值,然后将该数据传递给控制器,控制器将在其中将其返回到视图页面使用ViewBag。
这是模型:
public class usermodelR
{
public string TeaType { get; set; }
public string HotelType { get; set; }
}
这是控制器:
[HttpGet]
public ActionResult Radio()
{
return View();
}
[HttpPost]
public ActionResult Radio(usermodelR u)
{
ViewBag.TeaType = u.TeaType.ToString();
ViewBag.HotelType = u.HotelType.ToString();
return View();
}
这是视图:
@model helpers.Models.usermodelR
@using (Html.BeginForm("Radion","Home",FormMethod.Post))
{
Select Tea Type
Tea: @Html.RadioButton("TeaType","Tea",false)
| Coffee: @Html.RadioButton("TeaType","Coffee",true)
| BlackTea: @Html.RadioButton("TeaType","BlackTea",false)
| GreenTea: @Html.RadioButton("TeaType","GreenTea",false)
Select Hotel Type
Hotel Grand Plaza: @Html.RadioButton("HotelType","HotelGrandplaza",false)
| Hotel Lake View: @Html.RadioButton("HotelType","HotelLakeView",false)
| Hotel River Side: @Html.RadioButton("HotelType","HotelRiverSide",true)
| Hotel Mountain View: @Html.RadioButton("HotelType","HotelMountainView",false)
}
You Selected
Tea Type: @ViewBag.TeaType
Hotel Type: @ViewBag.HotelType
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)