2015-02-06 38 views
0

我使用c#web應用程序在mvc4中工作我們在web應用程序中有更多控制器和視圖,我們已經在route.config中爲所有控制器操作方法配置了路由文件作爲如何更改特定控制器的route.config文件中的url路由

routes.MapRoute(
    name: "Default", 
    url: "{controller}/{action}/{id}", 
    defaults: new { controller = "User", action = "Login", id = UrlParameter.Optional } 
); 

它在全國各地的應用程序中顯示像http://localhost:21638/WebFileViewer/WebDocumentViewer?fileId=21的網址,我們有一個控制器,它的任務是顯示由客戶端的網頁瀏覽器上傳的文件的文件瀏覽器頁面有鏈接像上面一個它顯示的網址,我想隱藏只有我將如何改變路由配置文件方面我要求該控制器的查詢字符串參數文件ID?

預期結果網址:http://localhost:21638/WebFileViewer/WebDocumentViewer

+1

這是什麼都與jQuery做?你也不能隱藏GET的參數。你可以改變你的代碼來使用POST請求。 – 2015-02-06 10:20:02

回答

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文件進行任何更改。

+0

當用戶刷新瀏覽器時怎麼辦? – 2015-02-06 10:42:41

+0

感謝它的運作 – 2015-02-06 10:44:10

+0

你是對的@StephenMuecke。感謝您指出了這一點。 – 2015-02-06 10:48:15

相關問題