asp.net mvc 3 - Partial View vs Json In MVC3 -
i using mvc3 razor new stuck below point.
in code giving ajax call using jquery json passing array of selected list on
button click on controller side , performing opration there , trying
call "partial view" can not see contents of partial view on page(not got render).
can on this.
jquery code:
$(function () { $('#btnadd').click(function () { var selectedlist = []; $("#ddlsupplementalcalculationlist option:selected").each(function (i, selected) { var $this = $(this); selectedlist.push({ id: $this.val(), value: $this.text() }); }); getcalculationlistgrid(selectedlist) }); }); function getcalculationlistgrid(selectedlist) { $.ajax( { url: "addselectedlist/supplementalpricing", type: "post", datatype: "json", traditional: true, data: {selectedlist: json.stringify(selectedlist)}, success: function (response) { } }); }
controller code:
public actionresult addselectedlist(string selectedlist) { var js = new javascriptserializer(); var deserializedselectedlist = (object[])js.deserializeobject(selectedlist); var selectedcalculationlist = new list<selectedcalculationlistmodel>(); if (deserializedselectedlist != null) { foreach (dictionary<string, object> calclist in deserializedselectedlist) { selectedcalculationlist.add(new selectedcalculationlistmodel(calclist)); } } list<assigncalculationssourcedatamodel> lstassigncalculationssourcedatamodel = new list<assigncalculationssourcedatamodel>(); assigncalculationssourcedatamodel assigncalculationssourcedatamodel = new assigncalculationssourcedatamodel(); assigncalculationssourcedatamodel.selectedcalculationnamescollection = selectedcalculationlist; lstassigncalculationssourcedatamodel.add(assigncalculationssourcedatamodel); return partialview("partialassigncalculationgrid", lstassigncalculationssourcedatamodel); }
partial view:
@model ilist<bnym.equinox.accounting.web.portal.models.pricing.assigncalculationssourcedatamodel>
@if (model != null) {
<div id="dvgrid"> <table id="grid" style="table-layout: fixed;"> <tr class="gridheaders"> <td colspan="13" align="center"> assigned calculations </td> </tr> <tr class="gridheaders"> <td colspan="4" style="width:212px"> assigned calculations usage </td> <td colspan="9" style="width:190px"> hirarchical pricing </td> </tr> <tr class="gridheaders"> <td class="checkbox" style="width:20px"> <input type="checkbox" name="selectall" id="selectall" onclick="checkall(this);" title="select all" /> </td> <td style="width:220px"> calculation name </td> <td class ="lblcalculationpurpose"> calculation purpose </td> <td class ="ddlroundingrules"> pricing calculation level </td> <td class ="ddlroundingrules"> rounding rule </td> <td class ="ddlroundingrules"> rounding type </td> <td class = "ddlroundingprecision"> precision </td> <td class = "txtassigncalculation"> investone security identifier </td> <td class = "txtassigncalculation"> hp rate source current </td> <td class = "txtassigncalculation"> hp rate source forward </td> <td class = "ddluserbank"> userbank </td> <td class = "txtassigncalculation"> hp rate time </td> <td class = "txtassigncalculation"> hp rate type </td> </tr> <tbody id="dvbody"> @for (var items = 0; items < model.count; items++) { (var item = 0; item < model [items].selectedcalculationnamescollection.count; item++) { (var index = 0; index < 3; index++) { var calculationpurpose = string.empty; <tr> <td style="width: 20px"> @html.checkbox("check", new { @id = "1", @class = "sel", @onclick = "uncheckheadercb(this);" }) </td> <td style="width: 220px"> @model[items].selectedcalculationnamescollection[item].value </td> <td class="lblcalculationpurpose"> @if (model[items].selectedcalculationpurpose.tolower().equals ("hp")) { if (index == 0) { calculationpurpose = "hp – trading nav"; @html.label(calculationpurpose) } else if (index == 1) { calculationpurpose = "hp - performance nav"; @html.label(calculationpurpose) } } else if (model[items].selectedcalculationpurpose.tolower ().equals("dissemination")) { calculationpurpose = "dissemination"; @model[items].selectedcalculationpurpose } else if (model[items].selectedcalculationpurpose.tolower ().equals("both")) { if (index == 0) { calculationpurpose = "hp – trading nav"; @html.label(calculationpurpose) } else if (index == 1) { calculationpurpose = "hp - performance nav"; @html.label(calculationpurpose) } else if (index == 2) { calculationpurpose = "dissemination"; @html.label(calculationpurpose) } } </td> <td class="ddlroundingrules"> @if ((model[items].selectedcalculationpurpose.tolower().equals ("both") && calculationpurpose.tolower().equals ("dissemination")) || model [items].selectedcalculationpurpose.tolower().equals("dissemination")) { if (model[items].pricingcalculationlevelscollection != null) { @html.dropdownlist("ddlcalculationlevel", new selectlist((system.collections.ienumerable)model [items].pricingcalculationlevelscollection, "id", "value"), new { @class = "ddlroundingrules" }) } } </td> @if ((model[items].selectedcalculationpurpose.tolower().equals ("both") && !calculationpurpose.tolower().equals("dissemination")) || model[items].selectedcalculationpurpose.tolower().equals("hp")) { <td class="ddlroundingrules"> @if (model[items].roundingrulescollection != null) { @html.dropdownlist("ddlroundingrule", new selectlist ((system.collections.ienumerable)model [items].roundingrulescollection, "id", "value"), new { @class = "ddlroundingrules" }) } </td> } else { <td class="tdbackground"></td> } @if ((model[items].selectedcalculationpurpose.tolower().equals ("both") && !calculationpurpose.tolower().equals("dissemination")) || model[items].selectedcalculationpurpose.tolower().equals("hp")) { <td class="ddlroundingrules"> @if (model[items].roundingtypescollection != null) { @html.dropdownlist("ddlroundingtypes", new selectlist ((system.collections.ienumerable)model [items].roundingtypescollection, "id", "value"), new { @class = "ddlroundingrules" }) } </td> } else { <td class="tdbackground"></td> } @if ((model[items].selectedcalculationpurpose.tolower().equals ("both") && !calculationpurpose.tolower().equals("dissemination")) || model [items].selectedcalculationpurpose.tolower().equals("hp")) { <td class="ddlroundingprecision"> @if (model[items].roundingprecisionscollection != null) { @html.dropdownlist("ddlroundingprecision", new selectlist ((system.collections.ienumerable)model [items].roundingprecisionscollection, "id", "value"), new { @class = "ddlroundingprecision" }) } </td> } else { <td class="tdbackground"></td> } @if ((model[items].selectedcalculationpurpose.tolower().equals ("both") && !calculationpurpose.tolower().equals("dissemination")) || model[items].selectedcalculationpurpose.tolower().equals("hp")) { <td class="txtassigncalculation"> @html.textbox("txtinvestonesecurityidentifier", "", new { @class = "txtassigncalculation" }) </td> } else { <td class="tdbackground"></td> } @if ((model[items].selectedcalculationpurpose.tolower().equals ("both") && !calculationpurpose.tolower().equals("dissemination")) || model[items].selectedcalculationpurpose.tolower().equals("hp")) { <td class="txtassigncalculation"> @html.textbox("txthpratesourcecurrent", "", new { @class = "txtassigncalculation" }) </td> } else { <td class="tdbackground"></td> } @if (model[items].selectedcalculationpurpose.tolower().equals ("hp")) { <td class="txtassigncalculation"> @html.textbox("txthpratesourceforward", "", new { @class = "txtassigncalculation" }) </td> } else { <td class="tdbackground"></td> } @if ((model[items].selectedcalculationpurpose.tolower().equals ("both") && !calculationpurpose.tolower().equals("dissemination")) || model[items].selectedcalculationpurpose.tolower().equals("hp")) { <td class="ddluserbank"> @if (model[items].userbankscollection != null) { @html.dropdownlist("ddluserbank", new selectlist ((system.collections.ienumerable)model [items].userbankscollection, "id", "value"), new { @class = "ddluserbank" }) } </td> } else { <td class="tdbackground"></td> } @if ((model[items].selectedcalculationpurpose.tolower().equals ("both") || model[items].selectedcalculationpurpose.tolower().equals ("hp")) && calculationpurpose.equals("hp - performance nav")) { <td class="ddluserbank"> @if (model[items].hpratetimecollection != null) { @html.dropdownlist("ddlhpratetime", new selectlist ((system.collections.ienumerable)model [items].hpratetimecollection, "id", "value"), new { @class = "ddluserbank" }) } </td> } else { <td class="tdbackground"></td> } } } } </tbody> </table> </div>
thanks in advance help
in success callback need handle response , insert recieved html page.
success: function (response) { $("#id_of_element_to_paste_response").html(response) }
and change type of request.
datatype: "html",
answer on comment. first need check response returned server. use fiddler or firebug or else.
if work fine , partial view returns on client successfuly, need edit jquery code.
$(function () { $('#btnadd').click(function () { var selectedlist = []; $("#ddlsupplementalcalculationlist option:selected").each(function (i, selected) { var $this = $(this); selectedlist.push({ id: $this.val(), value: $this.text() }); }); getcalculationlistgrid(selectedlist) }); }); function getcalculationlistgrid(selectedlist) { $.ajax( { url: "addselectedlist/supplementalpricing", type: "post", datatype: "html", //here edited traditional: true, data: {selectedlist: json.stringify(selectedlist)}, success: function (response) { $("#id_of_element_to_paste_response").html(response);//here edited } }); }
Comments
Post a Comment