1

according to the ASP.NET MVC Razor: How to render a Razor Partial View's HTML inside the controller action I'm can render a View to a string. But, is it possible to invoke an action inside the controller and render the result to a string ?

Community
  • 1
  • 1
Tony
  • 12,405
  • 36
  • 126
  • 226
  • Why? What are you trying to do? Consider using child actions. – SLaks Jul 19 '13 at 15:48
  • I'm trying to put that action result inside the Json response and update a DOM element on the client side. I don't want to use jquery in this scenario – Tony Jul 19 '13 at 15:50
  • Its hard understand what you try to do;) Is it ajax call? – maxs87 Jul 19 '13 at 15:58

1 Answers1

0

What I tend to do for things like this is return a PartialView which will have any of the HTML I need for the JavaScript to use. Keep in mind that in HTTP, everything is text already, so you don't need to do something special to render the result to a string to return to an AJAX call.

I'll have a PartialView which has the HTML I need, pass it back to the Ajax call using something like return PartialView("ViewName", model), then do whatever I need to on the client side - such as appending that HTML to a node in the DOM.

RebelFist
  • 549
  • 4
  • 11