RealityDysfunction
RealityDysfunction

Reputation: 2639

MVC routes, url changes

My page load initially using this url: https://somecoolwebsite.com/Forms/huge-hash

upon submission the url changes to: https://somecoolwebsite.com/Forms/Form

My routes setup is:

name: "Production",
url: "{id}",
defaults: new {controller = "Forms", action = "Create",id=UrlParameter.Optional}

name: "Default",
url: "{controller}/{action}/{id}",
defaults: new {controller = "Forms", action = "Create",id=UrlParameter.Optional}

My action to which the page posts does this at the end:

return View("Success");

this simply redirects to my success page. However the url says: https://somecoolwebsite.com/Forms/Form which is a problem because if the user hits refresh he gets an error.

How can I change the url to something else? Maybe https://somecoolwebsite.com/Success ?

Upvotes: 0

Views: 43

Answers (1)

Andy T
Andy T

Reputation: 9881

Instead of returning a view, simply redirect the user to that page:

return RedirectToAction("Success");


public ActionResult Success()
{
    return View();
}

Upvotes: 2

Related Questions