Posts

Showing posts with the label asp.net-mvc-3

How can I preserve the url (with the querystring) after an Http Post but also add an error to the Model State?

How can I preserve the url (with the querystring) after an Http Post but also add an error to the Model State? Essentially want I'm trying to do is authenticate a user by having them enter their account and their social security number. If they enter an incorrect combination, I do the following on the Authenticate post action: Authenticate ModelState.AddModelError("Authenticated", authenticationError); return View(); This displays the error, but then I lose what was in my query string. An alternative to keep the query string is: ModelState.AddModelError("Authenticated", authenticationError); return Redirect(Request.Url + "?returnUrl=" + returnUrl); This will keep the query string, but the error will not display. I assume this is because the ModelState has changed. ModelState I need the returnUrl because the user is forced to the Authenticate page whenever they click to view a specific event. I want to set it up so that they still go to this eve...