Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# &引用;“找不到资源”;尝试将提交的表单发布到ViewBag时出错_C#_Asp.net Mvc_Model View Controller - Fatal编程技术网

C# &引用;“找不到资源”;尝试将提交的表单发布到ViewBag时出错

C# &引用;“找不到资源”;尝试将提交的表单发布到ViewBag时出错,c#,asp.net-mvc,model-view-controller,C#,Asp.net Mvc,Model View Controller,我对MVC比较陌生,我试图在我的视图页面中创建一个表单,它允许我使用单选按钮选择数据值,然后将数据传递给控制器,控制器将使用ViewBag将数据返回到视图页面 这就是模型: public class UserModelR { public string TeaType { get; set; } public string HotelType { get; set; } } 这是控制器: [H

我对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

@模型助手.Models.usermodeler
@使用(Html.BeginForm(“radio”、“Home”、FormMethod.Post))
{
选茶

Tea:@Html.RadioButton(“TeaType”,“Tea”,false) |咖啡:@Html.RadioButton(“TeaType”,“Coffee”,true) |BlackTea:@Html.RadioButton(“TeaType”,“BlackTea”,false) |绿茶:@Html.RadioButton(“TeaType”,“GreenTea”,false)
选择酒店类型
大广场酒店:@Html.RadioButton(“HotelType”,“HotelGrandPlaza”,false) |酒店湖景:@Html.RadioButton(“HotelType”、“HotelLakeView”,false) |河畔酒店:@Html.RadioButton(“HotelType”,“HotelRiverSide”,true) |Hotel Mountain View:@Html.RadioButton(“HotelType”、“HotelMountain View”,false)
} 你选择了 茶型:@ViewBag.TeaType
酒店类型:@ViewBag.HotelType

当我单击“提交”时,它会将我重定向到“找不到资源”错误页面。

在Html.beg中,如果您正在发布一个名为Radio的操作,那么您的返回视图()表单Get和Post操作应该将一个模型作为参数传递。控制器中的操作名称(Radio)与.cshtml文件中的视图名称(Radio)不匹配。