0

In my MVC4 login view, I have several sections defined:

  • login - /User/Login#login or - /User/Login
  • register - /User/Login#register
  • lostpassword - - /User/Login#lostpassword

The JS on the page picks up the right form area to present.

Everything works fine for login - validation, etc. However if the registration fails, how do I return to the view with the added #register parameter?

-- Update -- I forgot to mention that this is from a controller and all validation errors need to be passed back to it. So, return Redirect("...") doesn't work

ElHaix
  • 12,846
  • 27
  • 115
  • 203
  • 1
    This should help: [How can I add an anchor tag to my URL?](http://stackoverflow.com/questions/7904835/how-can-i-add-an-anchor-tag-to-my-url) – Shad Nov 17 '13 at 20:24
  • @Shad - Thanks but see my update. Need to do this from a controller action. – ElHaix Nov 17 '13 at 20:53
  • 1
    Why not make it as a parameter ie. /User/Login/Register then map the route in your RouteRegistrar – Raymund Nov 17 '13 at 21:01
  • @Raymund - while that's a good idea, the route is `url: "User/Login#registerform"` , but the hashtag gets URL encoded. – ElHaix Nov 17 '13 at 22:00

2 Answers2

1

The following does the trick

return Redirect(Url.Action("Login", "User") + "#registerform");

URL is ~/Login/User#registerform.

ElHaix
  • 12,846
  • 27
  • 115
  • 203
0

This way will work:

return RedirectToAction("NewAction", new { 
     id = model.Id, 
     registerParam = model.registerId
});

PS: If New Action fails you can do the same thing back to the current action method, with some error parameter.

RealityDysfunction
  • 2,609
  • 3
  • 26
  • 53