Syed Yawar
Syed Yawar

Reputation: 113

Pass model via "redirect to action" visible to URL String in Browser

The thing is I'm passing some data in model from first action to second action of same controller but the data in model is visible in URL query string. this is the picture of action where I'm redirection some data

This is how it is visible to Query string enter image description here

Now

1 - is there any solution to hide that data in query string Other than using Temp Data

2 - and why redirection to action is happening from client ??

3 - It seems to be passing data via Get method in redirection, is there any way I can pass data in Body (i.e. Post).

Upvotes: 1

Views: 699

Answers (1)

ADyson
ADyson

Reputation: 61839

The MVC RedirectToAction method simply sends the client (browser, in this case) a HTTP header called "Location" in the response, and sets the status code to 302 "Found", to indicate a suggested redirect. That header contains the URL of the view you specified, and puts any model data onto the querystring.

The client can choose whether to visit that URL or not. Browsers generally follow the link automatically, because it's user-friendly to do so. Other HTTP clients may not do so. That's how it works - this is general to the whole web, not just MVC. The redirect is always done as a GET, it's not possible to redirect via any other HTTP method.

If you want to just display the view without a redirect, then use

return View("addLeaveEntitlement", result.Model)

Then there's just one request, there's no redirect, and the URL does not change at all (not even to the regular URL of the "add" view - this may or may not be desirable).

Upvotes: 3

Related Questions