Reputation: 773
I am new to asp.net MVC 4 . I just started demo app. Now my form is not posting here.
Here is my form
@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>
Here is my Routing
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 }
);
}
}
}
And here is My Home controller
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();
}
}
I tried making all changes still post method is not invoked when i keep the break point. Pls help me!
Upvotes: 3
Views: 3665
Reputation: 1150
You got just a button:
<input type="button" value="Submit Invitation" />
but should be submit:
<input type="submit" value="Submit Invitation" />
P.S. remove @ symbol before Html.BeginForm you already defined one in "using"
Upvotes: 4