c# - Entire MVC view loads on postback, instead of just partial view -
i trying build dashboard using mvc4. have populated dashboard view dashboard widgets rendered partial views using render.action().
<div class="row-fluid"> <div class="dashboard"> <div class="dashboard2col"> <div class="dashboardcol"> @for (int c1 = 0; c1 < model.count; c1 = c1 + 2) { html.renderaction("dashboarditem_" + model[c1].dashboardcode, "mydashboard", new { dashboardtitle = model[c1].dashboardtitle }); } </div> <div class="dashboardcol"> @for (int c2 = 1; c2 < model.count; c2 = c2 + 2) { html.renderaction("dashboarditem_" + model[c2].dashboardcode, "mydashboard", new { dashboardtitle = model[c2].dashboardtitle }); } </div> </div> </div>
each dashboard widget partial view has controller action method associated it, [childactiononly] attribute.
[childactiononly] public actionresult dashboarditem_allevents(string dashboardtitle) { di_allevents_vm model = new di_allevents_vm(); model.dashboardtitle = dashboardtitle; model.events = getallevents().where(x => x.isupdated == false).tolist(); return view(model); } [httppost] public actionresult dashboarditem_allevents(di_allevents_vm model, formcollection form) { foreach(var e in model.events) { if(e.ischecked) { var = model.events.where(x => x.eventid == e.eventid).firstordefault(); i.isupdated = true; } } session["events"] = model.events; var updatedevents = getallevents().where(x => x.isupdated == false).tolist(); model.events = updatedevents; return partialview("dashboarditem_allevents", model); }
the dashboard widget works fine creating read-only widgets. need create dashboard widget has search capability, needs post back. tried embedding partial view inside form submit button. when click on submit button, entire dashboard index page reloads instead of dashboard widget.
any suggestions?
research topic "ajax". basically, want write javascript captures submit event of form, , sends using xmlhttprequest() server, , server should reply data or html fragmet widget only.
Comments
Post a Comment