I have written some jquery which performs a get on an action, passing in a dashID and hopefully should have returned some html with the relevant information. However my jquery does not seem to be getting that data back.
Here is my javascript
function loadDashboard(dashID) {
$.get('@Url.Action("Dashboard", new {id = ' + dashID + '})', function (data) {
$('#dash-content').html(data);
});
}
I then wire up the javascript code to the onclick event on a html element
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
@foreach (var dashboard in Model.dashboard)
{
<li class="drop-text" onclick="loadDashboard(@dashboard.DashID)">@dashboard.DashName</li>
}
<li class="divider"></li>
<li class="drop-text" id="add-dashboard">Add dashboard</li>
</ul>
and the contents should be displayed here
<div id="dash-content">
@Html.Partial("Dashboard", Model);
</div>
and here is the controller
public ActionResult Dashboard(int? id)
{
var dashID = id;
if (dashID == null || dashID == 0)
{
dashID = 1;
}
var getWidgetsQuery = (from widgets in db.widgets
where widgets.DashID == dashID
select widgets);
dvm.widgets = getWidgetsQuery.ToList();
return PartialView(dvm);
}
I was following this post however it did not work for me MVC4 Update Partial view