asp.net mvc - DropDown change show partial -
i have used dropdownlist in page.
i want, when change selected id info, load bottom of page. first time page load true,but dropdown change load info in new page, not part of current page.
fill dropdown list
public actionresult selvahedlist(int idtype, int idchoose) { viewbag.chooseitem = idchoose; ienumerable<lcity> lcitys = dbcon.lcitys; var model = new cityviewmode { lcitys = lcitys.select(x => new selectlistitem { value = x.citycode.tostring(), text = x.cityname }) }; return view(model); });
partial view shows after dropdown changed
public actionresult selvahedlistajax(cityviewmode model) { int idcity=convert.toint32(model.selectedcitycode); // int idcity = 1; viewbag.reshteh = 1; //string idcity = base.request["selvalue"].tostring(); var res = dbcon.taavoniinfos.where(m => m.idreshteh == 1 && m.citycode ==idcity); return partialview("selvahedlistajax", res); }
view page
ajaxoptions ajaxopts = new ajaxoptions { updatetargetid = "loaddata", loadingelementid="loadadmin" }; @using (ajax.beginform("selvahedlistajax",ajaxopts)) { <fieldset> <div class="pcontent"> <p class="droplistcity" id="droplistcity"> @html.dropdownlistfor( x => x.selectedcitycode, new selectlist(model.lcitys, "value", "text","")) <div id="loaddata"> @html.action("selvahedlistajax", new { idreshte = viewbag.chooseitem }) </div> </div> </fieldset> } <script language="javascript" type="text/javascript"> $(document).ready(function () { $('#selectedcitycode').change(function () { this.form.submit(); }); }); </script>
thanks help
my partial view code is: @model ienumerable<taavons.models.taavoniinfo> <ul> @foreach (var item in model) { <li>:<b>@html.displayfor(modelitem => item.sname)</b></li> <li>:<b>@html.displayfor(modelitem => item.modirname)</b></li> <li><img src="@url.content("~/content/img/list16.png")" alt=""/> @html.actionlink("detail....", "detaild",new { codef= item.scode }, new { @class = "opendialog", data_dialog_id = "emaildialog", data_dialog_title = "" } ) <hr class="separatorline"/></li> when load page true after dropdownlist nt work <li> @if (!string.isnullorempty(item.tablighatpic)) { <img src="@url.content("~/content/img/eye.png")"/> @html.actionlink("تبلیغات....", "showimg", new { code = item.scode }, new { @class = "openimg", data_dialog_id = "maildialog" })<hr class="separatorline"/> } </li> } </ul>
i think need change ajaxoptions:
ajaxoptions ajaxopts = new ajaxoptions { updatetargetid = "loaddata", loadingelementid="loadadmin", insertionmode = insertionmode.replace // add line };
add parameter beginform call
@using (ajax.beginform("selvahedlistajax", new { idreshte = viewbag.chooseitem }, //add ajax.beginform call ajaxopts )) {
and remove line target div if don't want ajax call performed before user chooses anything
@html.action("selvahedlistajax", new { idreshte = viewbag.chooseitem })
Comments
Post a Comment