2010-04-05 134 views
0

給出的方法..將ActionResult返回給對話框。 ASP.NET MVC

public ActionResult Method() 
{ 
// program logic 
    if(condition) 
    { 
    // external library 
    // external library returns an ActionResult 
    } 

return View(viewname); 
} 

我無法控制的外部庫的返回類型或方法。我想抓住它的結果並在頁面上的對話框中處理 - 但我無法弄清楚如何返回到頁面來執行將負責它的jQuery。有任何想法嗎?

回答

2

你可以通過路由你的jQuery .ajax()請求來調用Method()。由於它只是直接返回html,因此請確保將響應類型設置爲期望值,然後您的jQuery回調處理程序將不得不處理生成的html。例如,

$("#myButton").click({ 
    $.ajax({ 
      // Basic ajax request properties 
      url: /* route to call Method() */, 
      data: {} 
      dataType: "html", 
      type: "GET", 
      success: function(objResponse){ 
        alert(objResponse); // alerts the html of the result 
        /* Deal with response here, put the html in a dialog */ 
      } 
     }) 
}); 
+0

我認爲這是我正在尋找的 - 但它仍然將用戶重定向到不同的頁面。有沒有什麼辦法可以阻止並強制頁面內容呈現對話框? – Ciel 2010-04-05 18:12:46

+0

這是一個jQuery的調用,所以它不應該在任何地方重定向。你有按鈕導航到一個網址? – Zaffiro 2010-04-05 21:12:48

相關問題