Hi here is my complete working solution.
Index view looks like the following:
@model BarClients.Models.BarClientsViewModel
@{
ViewBag.Title = "Index";
}
(many of the items for the Index view deleted here but Partial shown below).
@{Html.RenderAction("EmailAddressGrid", "Home");}
My Partial view _EmailAddressGrid.cshtml looks like the below:
@model BarClients.Models.BarClientsViewModel
@{
WebGrid grid = null;
if (Model.EmailAddressesOfChosenClient.Count<string>() != 0)
{
grid = new WebGrid(Model.EmailAddressesOfChosenClient, ajaxUpdateContainerId: "gridContent");
}
}
div id="gridContent" (arrows omitted)
@{ if (grid != null)
{
@grid.GetHtml() //work to be done here
}
}
div (arrows ommitted)
My two controller actions are as follows:
[HttpPost]
public ActionResult PopulateEmailAddressUI(string clientID)
{
_clientModel = InitialiseBarClientsModel();
_clientModel.FindEmailAddresses(from client in eFormsDB.BAR_Clients where client.ClientId == clientID select client);
return PartialView("~/Views/Shared/_EmailAddressGrid.cshtml", _clientModel);
}
public ActionResult EmailAddressGrid()
{
_clientModel = InitialiseBarClientsModel();
return PartialView("~/Views/Shared/_EmailAddressGrid.cshtml", _clientModel);
}
My jQuery function (working thanks to Jotabe) is as follows:
jQuery(document).ready(function () {
$("#MeditechDropDown").change(function () {
var id = $(this).find(":selected").val()
var clientID = { "clientID": id }
$.ajax({
url: "/Home/PopulateEmailAddressUI",
data: JSON.stringify(clientID), // Send value of the drop down change of option
type: 'POST',
datatype: 'html',
contentType: 'application/json; charset=utf-8',
success: function (response) {
$('#gridContent').html(response)
}
});
});
});
JotaBe's hints and some other web research got me here. I now get dynamically changing WebGrids on the Index view based on ClientIDs selected or reselected from my DropDownList in the Index view.