I am trying to build a dashboard using MVC4. I have populated my Dashboard view with the dashboard widgets rendered as 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 is a partial view that has a controller action method associated with it, with [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 i = 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 for creating read-only widgets. But I need to create a dashboard widget that has a search capability, so it needs to post back. I tried embedding the partial view inside a form with submit button. But when I click on the submit button, the entire Dashboard Index page reloads instead of just the dashboard widget.
Any suggestions?