2013-02-19 80 views
1

我的網站是在MVC3剃鬚刀和.Net 4框架。刪除url中的響應參數

我有一個href鏈接在我看來

<a href="http://localhost:17238/News?NewsID=20&NewsUrl=xxx">mylink</a> 

此鏈接到新聞行動和新聞行動是:

[ValidateInput(false)] 
    public ActionResult Index(int NewsID, string NewsUrl) 
    { 

     //do some process on NewsID and NewsUrl 

     mymodel mm=new mymodel(); 
     return View(mm); 

    } 

它工作正常,但返回的URL包括NewSID的和NewsUrl作爲參數,我知道 這是正常的,但如何從我的行動返回響應時刪除所有參數?

回答

2

要做到這一點的唯一方法是執行HTTP 302或301重定向。

return Redirect(); //302 
return RedirectPermanent(); //301 
return RedirectToAction(); //302 
return RedirectToActionPermanent(); //301 
return RedirectToRoute(); //302 
return RedirectToRoutePermanent(); //301 

通過執行一個HTTP重定向301你告訴客戶,這是一個永久重定向(即該資源已正式搬遷)。瀏覽器可能會緩存這個重定向。

你可能不想做301重定向;我只提到它給出一個完整的答案。

+0

是否可以通過在我的操作中編寫一些代碼? – motevalizadeh 2013-02-19 15:24:27

+0

@motevallizadeh - 當然,我在回答中給你添加了一些選項。 – 2013-02-19 15:27:18

+0

也可以從[這裏](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)閱讀301和302的更多內容, – Yasser 2013-02-19 16:55:59