【问题标题】:Hijacked Umbraco HttpPost action not firing劫持的 Umbraco HttpPost 操作未触发
【发布时间】:2014-04-10 08:06:59
【问题描述】:

我在 Umbraco 7.1 中劫持了路由,由于某种原因,按下提交按钮时我的 HttpPost 没有触发。关于为什么会这样的任何输入?按下发送时会发生回发,但在 HttpPost 中放置断点时不会触发。

这是我的代码的 sn-p,即控制器后面的标记。

@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();
}

【问题讨论】:

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


    【解决方案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();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-20
      • 1970-01-01
      • 1970-01-01
      • 2014-09-18
      • 2014-04-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多