我是asp.net MVC 4的新手。我刚开始演示应用程序。现在我的表格没有发布在这里。
这是我的表格
@model PartyInvites.Models.GuestResponse
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>InvitationForm</title>
</head>
<body>
@using (@Html.BeginForm("InvitationForm", "Home", FormMethod.Post))
{
<p>Your Name: @Html.TextBoxFor(x => x.Name)</p>
<p>Your Email: @Html.TextBoxFor(x => x.Email)</p>
<p>Your PhoneNo: @Html.TextBoxFor(x => x.PhoneNo)</p>
<p>
Will You Attend: @Html.DropDownListFor(x => x.WillAttend, new[]
{new SelectListItem(){Text="Yes",Value=bool.TrueString},new SelectListItem()
{Text="No",Value=bool.FalseString}}, "--SELECT--")
</p>
<input type="button" value="Submit Invitation" />
}
</body>
</html>
这是我的路由
namespace PartyInvites
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}
这是我的家庭控制器
public class HomeController : Controller
{
//
// GET: /Home/
public ViewResult Index()
{
int hour = DateTime.Now.Hour;
ViewBag.Greeting = hour > 12 ? "Afternon" : "Morning";
return View();
}
[HttpPost]
public ViewResult InvitationForm(GuestResponse guest)
{
return View("Thank You for Registration", guest);
}
[HttpGet]
public ViewResult InvitationForm()
{
return View();
}
}
当我保留断点时,我尝试进行所有更改 post 方法。请帮助我!
答案 0 :(得分:4)
你只有一个按钮:
<input type="button" value="Submit Invitation" />
但应该提交:
<input type="submit" value="Submit Invitation" />
P.S。在Html.BeginForm之前移除@符号你已经在“使用”中定义了一个