asp.net-mvc - 被劫持的 Umbraco HttpPost 操作未触发

标签 asp.net-mvc http-post umbraco

我在 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/

相关文章:

css - ActionLink 与 glyphicon-home

html - 防止div填充空白区域?

java - 通过 Http POST 请求从 Android 上传文件和其他数据

php - 使用从 iOS 设备发送的 multipart/form-data 检索 HTTP POST 变量

asp.net - 值 = 'p.Value' 抛出类型为 'System.NullReferenceException' 的异常

c# - 更正 JSON 结果对象

c# - Owin 使用外部表单例份验证 cookie

IOS > 使用 POST 在 Safari 中打开 URL

Umbraco.config 文件未被写入/发布

razor - 如何使用 Razor 在 Umbraco 中获取绝对媒体文件路径?