简体   繁体   English

输入提交抛出404以在MVC中找不到控件

[英]input submit throws 404 for control not found in MVC

I have published an MVC application to the server path '/iapps/ebiz'. 我已经将MVC应用程序发布到服务器路径“ / iapps / ebiz”。 The application works perfectly on localhost. 该应用程序可在localhost上完美运行。 The @Ajax.Action link is working as expected for the 'Get' operation and but '' is not finding the Post method for the controller and is throwing error code 404. @ Ajax.Action链接按“获取”操作的预期运行,但''找不到控制器的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"

    }

controller 控制者

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

Route Mapping 路线图

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

HTML shows 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">

Update: 04/08/2015 3:30PM 更新时间:04/08/2015 3:30 PM

Issue fixed if add if I add /eBiz/ (backslash) after eBiz in the browser. 如果在浏览器中的eBiz之后添加/eBiz/ (反斜杠),则添加时问题已解决。 If /eBiz and post is not working. 如果/eBiz和post不起作用。 How to fix this? 如何解决这个问题?

This trailingslash for base url issue. 基本URL问题的末尾加斜杠。

you had given the Route attribute as [Route("PostEditEmail")] so it will point to the URL 您已将Route属性指定为[Route(“ PostEditEmail”)],因此它将指向URL

/iapps/ebiz/PostEditEmail / iapps / ebiz / PostEditEmail

so that only your getting 404 error. 这样只有您收到404错误。 Try this 尝试这个

[Route("Customer/PostEditEmail")]

You are missing area parameter in Html.BeginForm .Try the following. 您在Html.BeginForm中缺少area参数。请Html.BeginForm以下操作。

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

Even if your controller is not under Area folder, you should add new { area = "" } in Html.BeginForm method 即使您的控制器不在Area文件夹下,您也应该在Html.BeginForm方法中添加new { area = "" }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM