I also encountered this problem when switching our project to the new Razor viewing engine. The approach I took was a little different because we had to generate JSON data from C # and wanted to output it when the page loaded.
In the end, I implemented RawView, which was parallel to View inside cshtml files. Essentially, to get the raw string,
@(new HtmlString(View.Foo)) // became @RawView.Foo
This requires a few changes in the layout of the project, so I just wrote a blog post about it here . In short, this required a duplicate implementation of MVC DynamicViewDataDictionary and a new WebViewPage that contains RawView. I also went ahead and implemented an index statement in RawView to allow
@RawView["Foo"]
In a random case, someone needs to iterate over data with a list of keys.
Reading a nurse's comment would probably be better if I called it Literal instead of RawView.
Anh-Kiet Ngo Aug 18 '10 at 22:21 2010-08-18 22:21
source share