问题
I want to hide the Querystring into My controller's action.
In my application scenariois something like this:
1) I have opened new action into new Window as:
var check="Particular String"
var url = rootUrl("Home/Preview?Docs=" + check);
window.open(url, '_blank');
2) On controller's Side I have used some code into Controller's action as:
public ActionResult Preview(string Docs)
{
TempData["Docs"] = Docs;
return RedirectToAction("UnInvoicedPreview");
}
My Query:: 1) when opening new window it shows the Query string in the Begining(uptill when it doesn't redirects to another action).
2) I dont want to show that QueryString into the URL.
3) Is there any way to hide the Query string or can we Encrypt that?
回答1:
no you cannot hide querystring at all.
instead of that there is many method
1. session["key"]
2. viewbag
3. $.post in jquery
4.
[HttpPost]
public ActionResult Preview(string Docs)
{
TempData["Docs"] = Docs;
return RedirectToAction("UnInvoicedPreview");
}
回答2:
- You can store data in session variables or try storing values in cookies.
It would be better to use TempData, which only allows the value to be used once (removed on first access). However, this implies the value will be used almost immediately.
encrypt the querystring.
回答3:
You can try this:
HttpServerUtility.UrlTokenEncode
and HttpServerUtility.UrlTokenDecode
to convert byte array to URL-safe string
回答4:
This is not very good MVC. MVC doesn't really use querystrings, except in special cases.
Suggested Url in MVC would be "/Home/Preview/<docsValue>"
That being said, if you want to hide the parameter, best to use jQuery and do a post to server.
var check="Particular String"
var data = "Docs=" + check;
$.post("/Home/Preview", data);
Note you can still see this value if you look at the view source of the page, but at least it won't show in the Url.
回答5:
Embed your page or portion of the page in IFrame this will hide the query string and URL altogether.
来源:https://stackoverflow.com/questions/21129954/hide-querystring-in-mvc-action