I can't figure out what I am doing wrong, I have a form in a partial view inside a layout and I can't get the controller to fire when the form is submitted, the form just posts to the localhost:54719/FormController/ExecutePost with the error
The controller for path '/FormController/ExecutePost' was not found or does not implement IController.
Layout Code : ~/Views/Shared/_Layout.cshtml
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>
@ViewBag.PageTitle
</title>
<link rel="stylesheet" media="all" href="/Content/style.css">
</head>
<body>
@Html.Partial("_Header");
<!-- / header -->
@Html.Action("Header", "Menu")
<!-- / navigation -->
@Html.Partial("_Form");
<!--Form -->
<div id="body">
@RenderBody();
</div>
<!-- / body -->
@Html.Partial("_Footer")
<!-- / footer -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script src="/Content/js/plugins.js"></script>
<script src="/Content/js/main.js"></script>
</body>
</html>
Form code : ~/Views/Shared/_Form.cshtml
@model MathsDoctor.Models.FormModel
@using (Html.BeginForm("ExecutePost", "FormController", FormMethod.Post))
{
<div class="form" id="find-form">
<fieldset><label>Telephone:</label>
@Html.TextBoxFor(model => model.Telephone)
@Html.ValidationMessageFor(model => model.Telephone)
</fieldset>
<fieldset><label>Name:</label>
@Html.TextBoxFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</fieldset>
<fieldset><label>Postcode:</label>
@Html.TextBoxFor(model => model.Postcode)
@Html.ValidationMessageFor(model => model.Postcode)
</fieldset>
<fieldset><input type="submit" value="SUBMIT">
</fieldset>
</div>
}
Form Controller : ~/Controllers/FormController.cs
public class FormController : Controller
{
//
// GET: /FindTutorForm/
[HttpPost]
public ActionResult ExecutePost(Models.FormModel formModel)
{
if (ModelState.IsValid)
{
return Redirect("/thanks/");
}
return PartialView("~/Views/Shared/_Form.cshtml");
}
}
I am sure I have missed something really simple...
Try
You have to remove the 'controller' part as it's automatically mapped.