I have 2 custom lists of radiobuttons on view, which I fill with cycles:
<div class="mutliSelectCat">
<ul>
@foreach (var cat in Model.Categories)
{
<li>
<label><input name="Category" type="radio" id=catid value=@cat.Name /> @cat.Name</label>
</li>
}
</ul>
</div>
<div class="mutliSelectSub">
<ul>
@foreach (var subCat in ViewBag.subs)
{
<li>
<label><input name="subCategory" type="radio" id=subcatid value=@subCat.Name /> @subCat.Name</label>
</li>
}
</ul>
</div>
So when I select an option in first list, I want to update the second list:
$('.mutliSelectCat input').on('click', function () {
var title = $(this).val();
$.get("/Review/GetSubCategories", { catname: title }, function (data) {
});
public ActionResult GetSubCategories(string catname)
{
ViewBag.subs = //getting data from db and sorting it
return Json(new { result = ViewBag.subs}, JsonRequestBehavior.AllowGet);
}
The question is: how can I update the list of subcategories? Can I somehow update the viewbag data on view, or I need to refresh "multiselectsub" div?