1

I created a simple form that works fine when I run it in Visual Studio, but fails on my website with a 404 error.

I have an Action set up to receive only "post" messages using [HttpPost]. If I change the Acton to receive "get" messages, the Action is called, but the form information is not passed along.

This site is written with .Net MVC, could there be some kind of security or something on the server that may need to be changed to allow for "post" calls?

Controller Code -

[HttpGet] public ActionResult Tester1() { return View("Tester1"); } [HttpPost] public ActionResult Tester2(MyModel myModel) { return View("Tester2", myModel); } 

Tester1.cshtml Code -

@model FS.Models.MyModel @using (Html.BeginForm("Tester2", "Comics", FormMethod.Post)) { <div> Enter Text - @Html.TextBoxFor(m => m.property1) </div> <div> <input type="submit" value="SEND!" /> </div> } 

Tester2.cshtml Code -

@model FS.Models.MyModel You entered - @Model.property1 

Global.asax.cs Code -

routes.MapRoute( "Tester2Route", // Route name "{controller}/Tester2", // URL with parameters new { controller = "Comics", action = "Tester2" } // Parameter defaults ); 

(the code above is just a summarized version, you can visit the actual site here - http://funkysmell.com/Comics/Tester1/)

5
  • Are you able to provide more details and maybe some code? It helps to get a picture of what is going on and less of a guessing game as to what they problem might be. Where necessary, use screenshots, detailed instructions to replicate the problem etc. Commented Jan 1, 2014 at 23:25
  • Rebuild your project and deploy the latest dlls in your server Commented Jan 2, 2014 at 0:12
  • 1
    your server is responding to the POST request with a 302 response code and redirecting you back to a GET request with the same URL. The 404 is a result of that. So you need to figure out why the 302 is occuring. Also, have you made modifications to your routes? Commented Jan 2, 2014 at 0:37
  • Hey Sean, I did add a route to the Global.asax.cs file. I will add the code in my question. Thanks! Commented Jan 2, 2014 at 0:43
  • Thanks for the reply, Shyju, I have rebuilt and deployed again, error still occurs. Commented Jan 2, 2014 at 0:46

1 Answer 1

1

I was able to get this to work.

The problem is that the server you are running on is wanting a trailing slash (/) after the URL. So when I looked at your example, the URL generated is

<form action="/Comics/Tester2" method="post"> 

If you add a trailing slash it will work. i.e.

<form action="/Comics/Tester2/" method="post"> 

Take a look here to get more information. Why is ASP.NET MVC ignoring my trailing slash? There are links in that answer to a few blogs which should help you out.

Sign up to request clarification or add additional context in comments.

1 Comment

That was it! Thanks, Sean! What a strange issue!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.