Answers for "asp.net mvc render multiple partial views"

C#
0

asp.net mvc render multiple partial views

// 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("<Your view name>", model);	
	}
}

// Or use JQuery:

$.ajax({
    type: "POST",
    url: '<Your URL>',
    contentType: "application/text; charset=utf-8",
    dataType: "text",
    success: function (data) {
        $("<Your container id>").html(data);
    },
    error: function (errData) {
      	// An error occured!
        $("<Your container id>").html(errData);
    }
});
Posted by: Guest on October-01-2020

C# Answers by Framework

Browse Popular Code Answers by Language