问题描述
我想不出什么我做错了,我有一个表格在布局内的局部视图,我无法得到控制时,提交表单,表单只是职位的本地主机火: 54719 /的FormController / ExecutePost与误差
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.
布局code:〜/查看/共享/ _Layout.cshtml
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>
表code:〜/查看/共享/ _Form.cshtml
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>
}
表单控制器:〜/控制器/ FormController.cs
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...
推荐答案
尝试
Html.BeginForm("ExecutePost", "Form", FormMethod.Post)
您必须删除'控制'的一部分,因为它的自动映射。
You have to remove the 'controller' part as it's automatically mapped.
这篇关于从局部视图MVC 3发布形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!