How to get view html and return to client side

后端 未结 3 940
太阳男子
太阳男子 2021-01-06 08:19

below is code snippet which return view to jquery function but i like to know how could i extract or get the view html and return to client end.

$(function(         


        
3条回答
  •  北海茫月
    2021-01-06 08:28

    You can make an AJAX call to the MVC action method, which will return the partial view as HTML. You then simply call the .html jquery function to populate your div. Something like this:

    $(function() {
      $('#myddl').change(function() {
        var url = $(this).data('url');
        var value = $(this).val();
    
        $.ajax({
          type: "POST",
          url: "@Url.Action("Foo", "Controller")", // replace with your actual controller and action
          data: JSON.stringify({ value: value }),
          success: function(result) {
            $('#result').html(result);
          }
      });
    });
    

提交回复
热议问题