📜  asp.net mvc 渲染多个局部视图 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:15.736000             🧑  作者: Mango

代码示例1
// You can't reutrn multiple partial views.
// However you can by pass this by simply looping a action

// in your .cshtml use Razor:

@{
      // Note! Using this method you can't pass JS variables;
    // they are loaded in runtime 
    int loopThisManyTimes = 10;
    for (int i = 0; i < loopThisManyTimes; i++)
    {
          MyModel model = new MyModel();
        Html.RenderPartial("", model);    
    }
}

// Or use JQuery:

$.ajax({
    type: "POST",
    url: '',
    contentType: "application/text; charset=utf-8",
    dataType: "text",
    success: function (data) {
        $("").html(data);
    },
    error: function (errData) {
          // An error occured!
        $("").html(errData);
    }
});