【问题标题】:MVC return multiple objects to jquery post data [duplicate]MVC将多个对象返回到jquery post数据[重复]
【发布时间】:2017-05-12 18:42:00
【问题描述】:

我正在尝试将多个对象传递给我的 jquery 发布数据对象,如下所示:

 return View("AffiliateManager", /*and now pass the JSON flag here*/);

“JSON 标志”就是这样:

Json("Ok"); => signaling that call was success

这样我就可以同时获取页面的 HTML 和我的 jquery 发布数据对象中的“OK”参数,如下所示:

 .done(function (data) {
                     if (data == "ErrorRequest") {
                         ShowErrorMessage("You don't have enough money to request payment!");
                         $('.btnRequestPayout').prop('disabled', false);
                         return;
                     }
                     else if(data=="Ok"){
                         ShowMessage("Payment request successfully made.");
                         $('.btnRequestPayout').prop('disabled', false);
                         var wholePage = $('<div />').append(data).find('#divPage').html();

                         $('#divPage').html(wholePage);
                     }
                 });

所以现在我有这样的数据对象:

data.html => whole HTML of the page
data.flag => signal whether the call was good

如何在 .NET MVC 中实现这一点?

【问题讨论】:

标签: javascript jquery asp.net asp.net-mvc asp.net-mvc-5


【解决方案1】:

你可以试试这段代码;

Json(new { html = "Html String Here" , flag = "Ok" } , JsonRequestBehavior.AllowGet);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-03
    • 1970-01-01
    • 2012-02-14
    • 1970-01-01
    相关资源
    最近更新 更多