JQuery - ASP.NET MVC -.load and RenderPartial

For some specific reasons, I need to use the load () method for jQuery to feed a web page in a div layer.

Most of these web pages are simple .html files.

However, for some, there is some data processing - I would like to be able to use the ASP.NET MVC model (which the site embeds), but this is not possible with simple .html pages - so I need to use .aspx / .ascx.

I am wondering if this can be done, does anyone know if I can load the layer that is extracted from .ascx ViewPage into ASP.NET MVC?

+4
source share
4 answers

The HTML code to be created using the view model can be executed with a partial view.

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

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

now on the html page use

 $.get("controller/partialview", {any data you want to send}, function(html) { $("#divToLoad").html(html); }); 
+7
source

You can also create a partial rendering method for static html files. You can check this question like: ASP.Net MVC: RenderPartial for static HTML file

+1
source

If I don’t understand something, you can easily do it in several ways.

For example, you can configure the route "...... / {filename} .html", which splashes the HTML file as a string, you can convert all HTML files to .ascx files and return a partial view ... etc . etc.

0
source

If I understand you well, all you have to do is get back

 PartialView() 

instead

 View() 

(or whatever you return under normal conditions) in the called action.

0
source

All Articles