4

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?

1
  • Can you elaborate a bit more please? I am not clear on what your asking. Commented Aug 27, 2009 at 18:43

4 Answers 4

7

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);
});
Sign up to request clarification or add additional context in comments.

Comments

1

You can create a render partial method for static html files also. You can check this question out on how: ASP.Net MVC: RenderPartial for a static HTML file

1 Comment

No, this isn't quite what I mean... I have an html file, and within it, I need to draw a partial view, or call upon one. It can't be an .aspx/.ascx, it has to be a .html file.
0

Unless I'm not understanding something, you could easily do this through a number of means.

For instance, you could setup a route of '....../{filename}.html' which spits out the HTML file as a string, you could convert all of the HTML files over to .ascx files and return a partial view.. and so on and so forth.

2 Comments

Can I bother you to elaborate on this? I'm very new to MVC's routing and what it can do/already does.
The biggest reason I cannot use a static .html file is because I need to do some work with a view model in some situations.
0

If I understand you well, all you have to do is to return

PartialView()

instead of

View()

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

1 Comment

I cannot use PartialView, It isn't being returned to an MVC page, it's being returned to a plain, normal .html page. That's my problem. I need to draw a partial view inside of a normal .html page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.