【问题标题】:Return ActionResult to a Dialog. ASP.NET MVC将 ActionResult 返回到对话框。 ASP.NET MVC
【发布时间】:2010-04-05 17:41:31
【问题描述】:

给定一个方法..

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

 return View(viewname);
}

我无法控制外部库的返回类型或方法。我想捕捉它的结果并在页面上的对话框中处理它 - 但我无法弄清楚如何返回页面以执行负责它的 jQuery。有什么想法吗?

【问题讨论】:

    标签: c# javascript jquery asp.net-mvc asp.net-mvc-2


    【解决方案1】:

    您可以通过将您的 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 */
                }
          })
    });
    

    【讨论】:

    • 我认为这是我正在寻找的 - 但它仍在将用户重定向到不同的页面。有什么方法可以阻止它并强制页面内容呈现在他的对话框中?
    • 这是一个 jquery 调用,因此它不应该将您重定向到任何地方。你有导航到 url 的按钮吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-02
    • 2014-02-11
    相关资源
    最近更新 更多