Ajax Result not Updating Web Grid Automatically MVC 4

匆匆过客 提交于 2019-12-25 05:36:17

问题


View Script

function AddToBag() 
    {
        var url = "/Home/Populate_Entitle/";
        $.ajax({
            url: url,
            data: { id: 1 },
            cache: false,
            type: "POST",
            success: function (data) {
                alert("hi");
                $("#gridContent").html(markup);
            },
            error: function (reponse) {
                alert("error : " + reponse);
            }
        });

    }

Controller Functions

public ActionResult Populate_Entitle(int id)
    {
        if (dtEntitle.Columns.Count == 0)
        {

            dtEntitle.Columns.Add("sno");
            dtEntitle.Columns.Add("Sport");
            dtEntitle.Columns.Add("Event");
            dtEntitle.Columns.Add("SubEvent");
            dtEntitle.Columns.Add("Classification");
            dtEntitle.Columns.Add("Entitlement");
            dtEntitle.Columns.Add("Channel");
            dtEntitle.Columns.Add("Brand");
            dtEntitle.Columns.Add("product");
            dtEntitle.Columns.Add("Unit");
            dtEntitle.Columns.Add("TotalSpots");
            dtEntitle.Columns.Add("TotalNetRevenue");
            dtEntitle.Columns.Add("remark");
            dtEntitle.Columns.Add("Sport_id");
            dtEntitle.Columns.Add("Event_id");
            dtEntitle.Columns.Add("SubEvent_id");
            dtEntitle.Columns.Add("channel_id");
            dtEntitle.Columns.Add("brand_id");
            dtEntitle.Columns.Add("product_id");
            dtEntitle.Columns.Add("Effective_Rate");
            dtEntitle.Columns.Add("Base_Rate");
        }
        DataRow dr = dtEntitle.NewRow();
        dr["sno"] = 1;
        dr["Sport"] = "Cricket";
        dr["Event"] = "IND vs BANGLADESH";
        dr["SubEvent"] = "1st Day 18-JUN-2015,2nd Day 20-JUN-2015";
        dr["Classification"] = "LIVE";
        dr["Entitlement"] = "Spot Buys";
        dr["Channel"] = "SS1,SS2";
        dr["Brand"] = "Brand 1";
        dr["product"] = "Product 1";
        dr["Unit"] = "Spots";
        dr["TotalSpots"] = 10;
        dr["TotalNetRevenue"] = 200 ;
        dr["remark"] = "-";
        dr["Sport_id"] = 1;
        dr["Event_id"] = 1;
        dr["channel_id"] = 1;
        dr["brand_id"] = 1;
        dr["product_id"] = 1;
        dr["Effective_Rate"] = 100;
        dr["Base_Rate"] = 100;
        dtEntitle.Rows.Add(dr);
        List<Sports_Deal.Models.Entitlements> lmdEntitle = new List<Sports_Deal.Models.Entitlements>();
        foreach (DataRow dr1 in dtEntitle.Rows) // loop for adding add from dataset to list<modeldata>
        {
            lmdEntitle.Add(new Sports_Deal.Models.Entitlements
            {
                 Event = dr1["Event"].ToString(),
                 Base_Rate = Convert.ToInt32(dr1["Base_rate"]),
                 brand_id = Convert.ToInt32(dr1["brand_id"]),
                 Brand = dr1["brand"].ToString(),
                 Channel = dr1["Channel"].ToString(),
                 Sport = dr1["Sport"].ToString(),
                 Effective_Rate = Convert.ToInt32(dr1["Effective_Rate"]),
                 channel_id =(dr1["channel_id"]).ToString(),
                 Quality = (dr1["channel_id"]).ToString(),
                 Classification = dr1["Classification"].ToString(),
                 Entitlement = dr1["Entitlement"].ToString(),
                 Event_id = Convert.ToInt32(dr1["Event_id"]),
                 product_id = Convert.ToInt32(dr1["Product_id"]),
                 remark = dr1["remark"].ToString(),
                 sno = Convert.ToInt32(dr1["sno"]),
                 Sport_id = Convert.ToInt32(dr1["Sport_id"]),
                 SubEvent = dr1["SubEvent"].ToString(),
                 SubEvent_id = dr1["SubEvent_id"].ToString (),
                 TotalNetRevenue = Convert.ToInt32( dr1["TotalNetRevenue"]),
                 TotalSpots = Convert.ToInt32(dr1["TotalSpots"]),
                 Unit = dr1["Unit"].ToString()
            });
        }

        return PartialView("markup", lmdEntitle);
    }
}

I need to populate Web grid dybamically when controller method returns list.


回答1:


Replace your markup with the Data

function AddToBag() {

    var url = "/Home/Populate_Entitle/";
    $.ajax({
        url: url,
        data: { id: 1 },
        cache: false,
        type: "POST",
        success: function (data) {
            alert("hi");
            $("#gridContent").html(data);
        },
        error: function (reponse) {
            alert("error : " + Json.stringify(reponse));
        }
    });

}

You are getting data in response, markup is undefined for this criteria



来源:https://stackoverflow.com/questions/31724557/ajax-result-not-updating-web-grid-automatically-mvc-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!