Mvc:没有被重定向到正确的视图

时间:2014-04-04 20:04:35

标签: c# asp.net-mvc asp.net-mvc-4 visual-studio-2012 razor

作为初学者,我正在做非常简单的MVC程序,在这个程序中,用户填写一个表单,并在ThankYou页面(视图)中接收这些值。

我的模特课

 namespace MvcPro1.Models
{
    public class GuestResponse
    {
        public string Name { get; set; }
        public string Email { get; set; }
        public string Phone { get; set; }
        public bool? willattend { get; set; }

    }
}

这是我Default1Controller

中表单的代码
[HttpGet]    
 public ViewResult RSVPForm()
        {
            return View(); 
        } 

当我右键单击并转到RSVPForm.cshtml

的视图时
<div>
        @using (Html.BeginForm())
        { 
            <p>Your Name @Html.TextBoxFor(x=>x.Name)</p>

            <p>Your Email @Html.TextBoxFor(y => y.Email)</p>
            <p>Your Phone @Html.TextBoxFor(z=>z.Phone) </p>

            <p>Will You attend ?</p>

            @Html.DropDownListFor(a=>a.willattend  , new []
            { 
                 new SelectListItem () {Text="Yes i willb be there ", Value= bool.TrueString }, 
                 new SelectListItem () {Text= "No i will not be ther ", Value  = bool.FalseString} , 

            },  "Choose an option "); 
            <input type="submit" value="Submit RSVP" />
        }
    </div>

你可以看到它的强类型视图。现在到get these values in my controller class我有

[HttpPost]
        public ViewResult RSVPForm(GuestResponse guest)
        {
            return View("ThankYou", guest);  
        }

这是view ThankYour.cshtml

    <div>

        Thank you @Model.Name . 
        if(@Model.willattend==true)
          Its great to listen you are coming , Drinkis are already in Fridge . 
        else 
           Sorry to hear you  cant come to attent 

    </div>

问题是,当我按下提交按钮,不带我到thankyou页面,而是它给404,当我尝试通过控制器转到视图(右键单击)去感谢页面,这也带我到我的表单视图不是谢谢你为此添加的,有人会帮我解决这个代码的错误。谢谢

1 个答案:

答案 0 :(得分:1)

嗯,你说你的观点叫做ThankYour.cshtml,但你回来的谢谢你可能就是这个问题