Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - ASP.NET MVC - .load and RenderPartial

For some specific reasons, I need to use the jQuery 'load()' method in order to feed a webpage into a div layer.

Most of these webpages are plain .html files.

However for some, there is some data processing going on - I would like to be able to leverage the ASP.NET MVC model (which the site is built in) - but that's not possible with plain .html pages - so I need to use .aspx/.ascx.

I'm wondering if this is doable, does anyone know if I can load a layer that is retrieved from an .ascx ViewPage in ASP.NET MVC?

like image 572
Ciel Avatar asked Mar 01 '23 10:03

Ciel


1 Answers

The html that you need to generate using the view model can be done in a partial view.

create the partial view (partialview.ascx) and in the controller create the method to get the ActionResult

public ActionResult partialview(){
   //your code
   return partialview(model);
}

now in your html page, use a

$.get("controller/partialview", {any data you want to send}, function(html) {
    $("#divToLoad").html(html);
});
like image 186
pyroglass Avatar answered Mar 13 '23 05:03

pyroglass