4

After a long search for a solution to this problem, I only found MVC5 and outdated solutions.

Now that we are in asp.net 5 beta 7, there are any way to render a view to a string variable ?

I need to render a view to show it in a bootbox javascript control (like a modal windows).

The MVC 5 solutions does not work in version 6 because there is no "ViewEngine" class in there. Look:

enter image description here

and even the Razor object can´t be found:

enter image description here

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
Beetlejuice
  • 4,292
  • 10
  • 58
  • 84
  • 1
    You'll have a better chance to get the dupe mark removed if you can update to explain why the known MVC5 options aren't possible in MVC6 – Jon Egerton Sep 21 '15 at 10:41
  • You're likely missing references - maybe `Microsoft.Aspnet.Mvc.ViewFeatures` and `Microsoft.Aspnet.Mvc.Razor`. You can have a dig around the [github repo](https://github.com/aspnet/Mvc) to find exactly what you want, including checking the unit tests to see what they reference. – Jon Egerton Sep 21 '15 at 10:56
  • 1
    Hi @Jon, are you sure you using mvc 6 ? A lot of things changes. – Beetlejuice Sep 21 '15 at 11:36
  • 2
    @paulo Yep - but its all beta, so you'll need to hunt around a little for it. According to the page linked, the `Razor.Parse` method uses a `RazorEngine` library which looks like it's being updated for Razor4 and Roslyn. – Jon Egerton Sep 21 '15 at 12:26
  • 1
    So basically your question is _"Which references and usings do I need to make this code work"_? You also **really** don't need to render a view to string, you can make an AJAX request to get the popup's contents. – CodeCaster Sep 21 '15 at 12:29
  • why dont you just use a partial view ? – Thorarins Sep 21 '15 at 12:40

1 Answers1

4

You can use this approach (see RenderPartialViewToString): https://stackoverflow.com/a/32577016/2631076

Community
  • 1
  • 1
hcp
  • 3,268
  • 6
  • 26
  • 41