Reputation: 45911
I'm developing an ASP.NET MVC application with C# and .NET Framework 4.7.
I have this redirect:
return RedirectToAction("Index", "ProductionOrder", new { isWizard = viewModel.IsWizard });
And this is the signature of the method ProductionOrderController.Index
:
// GET: ProductionOrder
public ActionResult Index(bool isWizard = false)
When I call this method on my web browser I get this URL:
http://VANSFANNEL:53827/ProductionOrder?isWizard=True
Is there a way to hidden the parameter isWizard
and don't show it in the URL?
Upvotes: 1
Views: 68
Reputation: 446
In this scenario, what you really should be doing is return a view rather than redirect.
Like:
return View(viewModel);
But if you really prefer to do a redirect, you can place the ViewModel in the TempData, and then redirect to the action:
TempData["MyViewModelFromRedirect"] = viewModel;
And in your redirected action:
var ViewModel = (MyViewModel)TempData["MyViewModelFromRedirect"];
Upvotes: 1
Reputation: 156918
No, there is not. A redirect is always an HTTP GET, so you can't POST the parameter which kind-of hides it.
I don't know your exact requirements, but if you can rewrite the code to become a POST, that would be the easiest way to remove the parameter from the URL. Else you might want to save it somewhere else: in a session variable or obfuscate the value so you can de-hash it later on.
Upvotes: 3