Render Partial Views using JQuery in MVC3

前端 未结 2 1652
栀梦
栀梦 2021-01-15 18:15

I have some records. Upon clicking on every record there information needs to display in an accordion.

That information is supposed to fetch from database dynamicall

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-15 18:47

    this is a basic approach when you need submit some form and render the partial view as result

    function GetView(){
    if ($('#MyHtmlForm').valid()){
        $.ajax(
        {
          type: "POST",
          url: $('#MyHtmlForm').attr("action"), 
          data: $('#MyHtmlForm').serialize(),
          success: function(result) {
            //Render the partial view
            }
          },
          error: function(req, status, err) {
            //handle the error
          }
        });
    }
    

    }

    and this for get basic details of row via json format, so use javascritp to generate the html

    function GetSomeData() {
    var cod = $('.row').val();
    $.getJSON('@Url.action("ActionName","Controller")', { cod: cod }, function (result) {
        //Render data
    });
    

    }

提交回复
热议问题