我在 Umbraco 7.1 中劫持了路由,并且由于某种原因,按下提交按钮时我的 HttpPost 没有触发。有什么意见可以解释为什么会这样吗?当按下发送时会发生回发,但在 HttpPost 中放置断点时它永远不会被触发。
这是我的代码片段,标记后跟 Controller 。
@inherits UmbracoViewPage
@{
Layout = "Layout.cshtml";
}
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.TextAreaFor(m => m.Message)
< i n p u t type="submit" value="Send" />
@Html.ValidationMessageFor(m => m.Message)
</div>
}
public ActionResult Index(ManageMessageId? smess)
{
var errorModel = new ErrorModel();
...
return CurrentTemplate(errorModel);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Index(ErrorModel model)
{
if (ModelState.IsValid)
{
...
}
return View();
}
最佳答案
假设您正在使用 SurfaceController,您需要按如下方式创建表单。请注意创建表单的方式以及泛型和参数如何与表面 Controller 相匹配的变化:
@using (Html.BeginUmbracoForm<MyController>("Index"))
{
}
你的 Controller 应该看起来像:
public class MyController : SurfaceController
{
public ActionResult Index(ManageMessageId? smess)
{
var errorModel = new ErrorModel();
...
return CurrentTemplate(errorModel);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Index(ErrorModel model)
{
if (ModelState.IsValid)
{
...
}
return View();
}
}
关于asp.net-mvc - 被劫持的 Umbraco HttpPost 操作未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22982223/