簡體   English   中英

將ActionResult返回到對話框。 ASP.NET MVC

[英]Return ActionResult to a Dialog. ASP.NET MVC

給定一種方法

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

 return View(viewname);
}

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

您可以通過僅將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 */
            }
      })
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM