2011-05-19 64 views

回答

2

您可能可以在AddComment Action上獲取URL引用,然後重定向到該引用。

例如

public ActionResult AddComment(int blogId){ 
    var referer = Request.UrlReferrer; 
    ViewBag.Referrer = referer; 
    Return View(); 
} 

或者你可以傳遞有關ReturnUrl查詢字符串的上網本。因此,如果您點擊博客文章頁面上的按鈕或鏈接添加評論,則可以添加[email protected]然後,您可以在POST ActionResult上訪問此項。

// Get 
public ActionResult AddComment(int blogId, string returnUrl){   
    Return View(); 
} 

[HttpPost] 
public ActionResult AddComment(BlogComment blogComment, string returnUrl){ 
    // do your stuff then redirect to the return url. 
} 
+0

謝謝。 – VJAI 2011-05-19 13:25:29

+2

我在這裏得到了一個鏈接將幫助他人http://stackoverflow.com/questions/1471188/how-do-i-get-the-referrer-url-in-an-asp-net-mvc-action – VJAI 2011-05-19 13:47:01

+0

這並沒有'覆蓋足夠的細節。 – SepehrM 2015-03-31 20:25:47