【问题标题】:input submit throws 404 for control not found in MVC在 MVC 中找不到控件的输入提交抛出 404
【发布时间】:2015-04-08 18:16:15
【问题描述】:

我已将 MVC 应用程序发布到服务器路径“/iapps/ebiz”。该应用程序在本地主机上完美运行。 @Ajax.Action 链接在“Get”操作中按预期工作,但“”没有找到控制器的 Post 方法,并抛出错误代码 404。

  @Ajax.ActionLink(
                     "Add Email",
                    "GetEditEmail","Customer",
                              new { CommunicationLocation = "add" },
                     new AjaxOptions()
                            {
                                HttpMethod = "Get",
                                UpdateTargetId = "DivEmailContainer",
                                InsertionMode = InsertionMode.Replace
                            },
                      new { @class = "btn btn-success" })      </td>



 @using (Html.BeginForm("PostEditEmail","Customer", FormMethod.Post, new { name = "frmEmail", id = "frmEmail" }))
    {

    <input type="submit" value="Save" class="btn btn-success" /> 
      <!-- This one is going "/iapps/Customer" but suppose to be "/iapps/eBiz/Customer"

    }

控制器

 [HttpGet]
 public PartialViewResult GetEditEmail(string CommunicationLocation)
 {
 }
 [HttpPost]
 [Route("PostEditEmail")]
 public PartialViewResult PostEditEmail(string Actiontype,  FormCollection col)
 {
 }

路线图

 routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Customer", action = "Index", id = UrlParameter.Optional }
        );

HTML 显示

<form action="/iapps/ebiz/Customer/PostEditEmail?Length=8" data-ajax="true" data-ajax-method="Post" data-ajax-mode="replace" data-ajax-update="#DivEmailContainer" id="frmEmail" method="post" name="frmEmail" novalidate="novalidate" _lpchecked="1">

更新:2015 年 4 月 8 日下午 3:30

如果我在浏览器中的 eBiz 之后添加 /eBiz/(反斜杠),则问题已修复。如果/eBiz 和帖子不起作用。如何解决这个问题?

此尾随斜杠表示基本 url 问题。

【问题讨论】:

  • 你创建的虚拟目录路径是ebiz吗

标签: c# asp.net ajax asp.net-mvc asp.net-mvc-4


【解决方案1】:

您已将 Route 属性指定为 [Route("PostEditEmail")],因此它将指向 URL

/iapps/ebiz/PostEditEmail

所以只有你得到 404 错误。试试这个

[Route("Customer/PostEditEmail")]

【讨论】:

  • 但它正在运行iapps/customer/PostEditEmail。完全无视ebiz
【解决方案2】:

Html.BeginForm 中缺少area 参数。请尝试以下操作。

@using (Html.BeginForm("PostEditEmail","Customer", new { area = "eBiz" }, FormMethod.Post, new { name = "frmEmail", id = "frmEmail" }))
    {    
        <input type="submit" value="Save" class="btn btn-success" />
    }

即使你的控制器不在Area文件夹下,你也应该在Html.BeginForm方法中添加new { area = "" }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 2016-05-09
    • 2016-06-25
    • 1970-01-01
    • 1970-01-01
    • 2017-12-21
    • 2013-12-28
    相关资源
    最近更新 更多