Home Refreshing data in ViewBag
Reply: 0

Refreshing data in ViewBag

user1391
1#
user1391 Published in May 23, 2018, 8:13 pm

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?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.327789 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO