Hide Querystring in MVC action

心已入冬 提交于 2019-12-06 12:10:16
MaTya

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");
}
  1. You can store data in session variables or try storing values in cookies.

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

  3. encrypt the querystring.

You can try this:

HttpServerUtility.UrlTokenEncode and HttpServerUtility.UrlTokenDecode to convert byte array to URL-safe string

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.

Embed your page or portion of the page in IFrame this will hide the query string and URL altogether.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!