我使用c#web应用程序在mvc4中工作我们在我们的Web应用程序中有更多的控制器和视图,我们已经为route.config文件中的所有控制器操作方法配置了路径
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "User", action = "Login", id = UrlParameter.Optional }
);
它在整个应用程序中显示类似http://localhost:21638/WebFileViewer/WebDocumentViewer?fileId=21
的URL,我们有一个控制器,任务是显示客户端在Web浏览器中上传的文件,文件查看器页面有url,就像上面显示的那样在url中的文件ID,我想隐藏此控制器的查询字符串参数,我将如何更改路由配置文件以满足我的要求?
预期结果网址:http://localhost:21638/WebFileViewer/WebDocumentViewer
答案 0 :(得分:2)
您可以使用TempData
:
TempData["FileId"] = "bla";
//this will make sure the data is kept when the user refreshes the page
TempData.Keep();
RedirectToAction("WebDocumentViewer", "WebFileViewer");
然后在WebDocumentViewer
中检索TempData["FileId"]
的值。
您不必对RouteConfig.cs
文件进行任何更改。