【发布时间】:2017-01-18 09:23:43
【问题描述】:
我的 Contact_Us 视图中有这样的表格
@model vidiaweb_com.Models.Contact_US
....
<div id="contactus">
<div class="container">
<form class="form-group col-md-8">
<div id="contactuspost">
<h3 class="txtformat">Contact Us</h3>
<p class="txtformat">
We are here to answer any questions you may have. Reach out to us and we will respond as soon as we can.
</p>
<p class="txtformat">
Even if there is something you have always wanted to experience and can't find it on combadi, let us know and we promise we'll do our best to find it for you and send you there.
</p>
<br />
<div class="form">
@using (Html.BeginForm("Create", "Contact_Us"))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<div class="form-group">
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2 txtformat" })
<div class="col-md-12">
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
</div>
....
</div>
}
</div>
</div>
</form>
</div>
</div>
....
@Html.Partial("_MainFooter")
这是我的 Contact_UsController
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "Id,Name,Email,Phone,Message,Date")] Contact_US contact_US)
{
if (ModelState.IsValid)
{
db.Contact_US.Add(contact_US);
db.SaveChanges();
return RedirectToAction("Index","Home");
}
return RedirectToAction("Index", "Home");
}
但在我填写表单然后单击提交按钮时,它不会在Contact_Us 控制器中调用Create 操作。像这样的东西在我的网址中
http://localhost:50074/Contact_Us/Index?__RequestVerificationToken=nrlDXOQglmGEzSQMqOqxm8ol4GiKeLffHoQUnLmuwhlIGcSFQfBrQxhZA8EL39nPLmG1FJQK42X284v60l6oepOytsmHLgwDOJYOgfmYnFU1&Name=dg&Email=d%40d.com&Phone=SF&Date=&Message=SFD
它会再次重定向到我的 Contact_Us 索引视图中。
我的项目中有另一种形式,但它可以正常工作。有谁知道问题可能是什么?谢谢
【问题讨论】:
-
这是您认为的唯一形式吗? (看起来您可能有无效的嵌套表单)。是
Index()方法生成了这个视图吗? -
是的@StephenMuecke 我认为只有这一种形式。感谢您的关心
-
你确定吗?你能发布整个视图吗?
-
是的,请稍等编辑@StephenMuecke
-
您确实有嵌套表单 :) - 删除外部
<form class="form-group col-md-8">
标签: asp.net asp.net-mvc forms post