被劫持的Umbraco HttpPost行动没有​​开火

时间:2014-04-10 08:06:59

标签: asp.net-mvc http-post umbraco

我在Umbraco 7.1中劫持了这条路线,由于某种原因,当按下提交按钮时,我的HttpPost没有被触发。有关为什么会这样的任何输入?按下发送时会发生回发,但是当在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();
}

1 个答案:

答案 0 :(得分:1)

假设您使用的是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();
    }
}