简体   繁体   中英

HTTP Error 405.0 - Method not allowed error in asp.net mvc 4 post method

I have an existing asp.net mvc 4 solution. It has several controllers/models/views in separate folders and all work fine with both GET and POST controller methods. I have added a new folder and added its own controllers/models/views. When I call the GET controller method, from the view it works fine. But the POST controller method throws

HTTP Error 405.0 - Method not allowed. The page you are looking for cannot be displayed because an invalid method (HHTP verb) is being used.

The following is my view and controller

<div id="usercreds" class="items">
   @using (Html.BeginForm("SaveCustomer", "NewCustomer"))
   {
        //form control code here               
   }

   [HttpPost]
   public ActionResult SaveCustomer(NewCustomerModel newCustomer)
   {
        //more code here
   }

I added FormMethod.Post in the Html.BeginForm method and added modules="IsapiModule" in web.config file

I still get the same error.

The issue was there were two identically named folders within the VisualStudio solution. Because of this it was posting to the wrong URL. I renamed one of the folders and it worked fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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