我已经在Umbraco 7.1中劫持了该路由,由于某些原因,当按下“提交”按钮时,我的HttpPost没有启动。关于这是为什么的任何输入?按下send时会发生回发,但是在HttpPost中放置断点时不会触发。
这是我的代码的片段,控制器后面是标记。
@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();
}
最佳答案
假设您正在使用SurfaceControllers,则需要按以下方式创建表单。请注意创建表单的方式以及通用和参数与表面控制器的匹配方式的变化:
@using (Html.BeginUmbracoForm<MyController>("Index"))
{
}
您的控制器应类似于:
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/