-1

enter image description here

I need to generate HTML(cshtml) page when I call asp.net controller by Ajax, and after generated page, I want to update a Iframe src to the generated page.

but I couldn't find how to generate the cshtml page dynamically.

anybody know please advice me.

Thank You!

[EDIT]

I can not call the generatePage in IFrame because I need to pass too many parameters to the controller. so I need to use POST method. so I thought I need to generate the page first using Ajax POST call and load the page in IFrame.

Expert wanna be
  • 10,218
  • 26
  • 105
  • 158
  • take a look to my answer that's something similar http://stackoverflow.com/questions/8992721/how-to-call-url-action-in-mvc-with-javascript-function/8992960#8992960 – Jorge Jul 03 '12 at 14:00
  • Do you mean you want to compose a .cshtml on-the-fly and then call it? Why not just build the HTML in code in the first place? – bluevector Jul 03 '12 at 14:04
  • better yet, why not just return a view and have your view build out your html as you need it? Similar to Rohan below, but customize the created html view to work with whatever parameters. Im gathering you are new to MVC, so I'll avoid discussion of ViewModels and packaging all data for your view here, but don't forget the V in MVC here. – Adam Tuliper Jul 03 '12 at 14:34

2 Answers2

1

Well sorry if I misunderstood a question, but if you need to load a View(that already exists) using Ajax and insert it into the page check this out:

Render partial view to string Renders partial view on server to html string, useful when you need to add partial view to ASP.NET MVC page via AJAX.

formatc
  • 4,261
  • 7
  • 43
  • 81
0

I't seems to me like this is your issue, but excuse me if i completely missed the point.

Right click on View, and say add view.

public ViewResult Index()
{
   return View();
}

Also, if you right click in your solution explorer on the controller folder and say add controller, you get a few options. These templates can be overridden, but that's a story for another day :P

Rohan Büchner
  • 5,333
  • 4
  • 62
  • 106