1

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).

Syed Yawar
  • 103
  • 1
  • 9
  • 1
    Just pass an ID to the `addLeaveEntitlement(int id)` method and get the object again (and you cannot redirect to a POST method) –  Mar 26 '18 at 11:40
  • @StephenMuecke Why it is redirecting through client ? why not just internally? – Syed Yawar Mar 26 '18 at 11:41
  • Because that is the way the web works - your making a redirect :) –  Mar 26 '18 at 11:44
  • Possible Duplicate of [this](https://stackoverflow.com/questions/46582/response-redirect-with-post-instead-of-get) – ChiragMM Mar 26 '18 at 11:45

1 Answers1

3

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).

ADyson
  • 57,178
  • 14
  • 51
  • 63
  • 2
    Re using `return View()` to display a different view - generally it would not be desirable - the 'addLeaveEntitlement` url is not added to the browser history, and if the user bookmarked it, it would return the wrong url. –  Mar 26 '18 at 23:59