Dynamically load Partial Views

后端 未结 6 999
醉话见心
醉话见心 2020-12-14 16:58

How can i dynamically load a Partial View?

I mean I have this view, lets say ListProducts, there I select some dropdownlists with products, etc, and wit

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-14 17:30

    I believe you can do something like this example, just using the change event on your dropdown instead. It's a simple jQuery call, you can find more on the jQuery website.

    $("#dropdown").change(function() {
    
        $("#destination").load("/Products/GetProduct", $(this).val(),
           function(result) {
             // do what you need to do
    
           });
    });
    

    The first parameter is the view you need to call for the details.

    The second parameter is the selected value.

    The third parameter of the $.load function is the callback function, where you can parse the result and do what you need to do.

    If you have a multiple select $(this).val() that will give you an array with the selected options.

    If you want only return a Json object you may want to follow this example.

提交回复
热议问题