如何解决尝试将已提交的表单发布到ViewBag中时出现“找不到资源”错误
我是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 举报,一经查实,本站将立刻删除。