viewengine

Add custom viewengine to New project dialog?

旧时模样 提交于 2019-12-02 13:27:09
问题 When creating a new project for MVC3 I have an option to select a custom viewengine. I can choose between Razor and ASPX . Is there a way to add Spark to the dropdownlist? 回答1: The short answer is: No, not really. The long answer is: Yes, but there's a catch and it requires registry edits. The New Project Dialog is built around the idea of selecting a projecttemplate first and then selecting a view-engine supported by that template. Others have managed to add their own things to this window,

Extending WebFormView in MVC

蹲街弑〆低调 提交于 2019-12-02 10:17:10
I want to extend the WebFormViewEngine so that I can perform some post-processing - I want it to do it's stuff, then hand me the Html back, so I can do put some final touches to it. It needs to be done as a View/ViewEngine because I need access to the ViewData. Unfortunately there seems to be no way to get the Html back from the WebFormView, and no way to hand a custom HtmlTextWriter to the WebFormView or ViewPage. Surely there's a way to do this? No? Littlecharva You can use Action Filters to do this. Check out this tutorial at asp.net/mvc. You want to use a ResultsFilter. As an alternate,

How to make razor the default view engine in existing project

南笙酒味 提交于 2019-12-02 00:12:33
I upgraded an MVC 2 project to MVC 3. How can I set the default view engine to Razor on an existing project? Edit: Sorry, I was rather unclear. I want to have Razor be the default type in the Add View dialog. The Add View dialog should default to a Razor selection in the view engine combobox if your project has at least one Razor file already or if it has no Aspx files (i.e. a project with no view files at all). Are you not seeing that behavior? Short answer: Change in global.asax to use both webforms and razor: ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new RazorViewEngine());

HTML Encoding Strings - ASP.NET Web Forms VS Razor View Engine

删除回忆录丶 提交于 2019-12-01 15:35:20
I'm not quite sure how this works yet... trying to find documentation. In my existing app I've got two different ways of rendering strings in my View <%: model.something %> <!-- or --> <%= model.something %> The first one is html encoded, and the second one is not. Is there something similarly short in Razor? All I can find is this, which is the encoded version. @model.something I guess the best approach would be to use the Raw extension-method: @Html.Raw(Model.Something) @Model.Something automatically HTML encodes. If you want to avoid HTML encoding (and you want this only if you are

HTML Encoding Strings - ASP.NET Web Forms VS Razor View Engine

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 13:41:16
问题 I'm not quite sure how this works yet... trying to find documentation. In my existing app I've got two different ways of rendering strings in my View <%: model.something %> <!-- or --> <%= model.something %> The first one is html encoded, and the second one is not. Is there something similarly short in Razor? All I can find is this, which is the encoded version. @model.something 回答1: I guess the best approach would be to use the Raw extension-method: @Html.Raw(Model.Something) 回答2: @Model

How to write a Visual Studio extension for a template or markup language that supports embedded code snippets

橙三吉。 提交于 2019-11-30 17:33:07
Is it possible to write an extension for Visual Studio 2010 that provides syntax highlighting, intellisense, outlining, etc for a custom template or markup language supporting embedded code snippets , similar to the tooling for Razor in ASP .NET MVC 3? Can this be done without using private APIs, without access to Microsoft-internal documentation and, most importantly , without having to reimplement syntax highlighting, intellisense, etc. for the embedded programming language (i.e. C# or VB)? The SDK documentation seems to suggest that the Visual Studio editor supports embedded languages via

Render partial view to string MVC4

♀尐吖头ヾ 提交于 2019-11-30 14:29:33
I am using the following to render a partial view to a string... protected string RenderPartialViewToString(string viewName, object model) { if (string.IsNullOrEmpty(viewName)) viewName = ControllerContext.RouteData.GetRequiredString("action"); ViewData.Model = model; using (var sw = new StringWriter()) { ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName); var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw); viewResult.View.Render(viewContext, sw); return sw.GetStringBuilder().ToString(); } } However it

alternative asp.net MVC view engines

风流意气都作罢 提交于 2019-11-30 09:47:51
I was wondering if there was a general consensus on the "best" alternative view engine for asp.net MVC. So far I know of Spark, Brail, NHaml but what about others? I would suggest that you take each of the above View Engines, write a view, and see which works best for you. You might find that for different applications or even for differnt types of view that the choice of View Engine changes. If you're returning HTML to your client then an engine like Spark might be appropriate. However, if the conent you're returning is XML or some other markup (JSON for example) then Spark won't be much help

Razor Nested Layouts with Cascading Sections

醉酒当歌 提交于 2019-11-30 06:17:20
问题 I have an MVC3 site using Razor as its view engine. I want my site to be skinnable. Most of the possible skins are similar enough that they can derive from a shared master layout. Therefore, I am considering this design: However, I would like to be able to call RenderSection in the bottom layer, _Common.cshtml , and have it render a section that is defined in the top layer, Detail.cshtml . This doesn't work: RenderSection apparently only renders sections that are defined the next layer up. Of

How to write a Visual Studio extension for a template or markup language that supports embedded code snippets

假装没事ソ 提交于 2019-11-30 01:19:21
问题 Is it possible to write an extension for Visual Studio 2010 that provides syntax highlighting, intellisense, outlining, etc for a custom template or markup language supporting embedded code snippets , similar to the tooling for Razor in ASP .NET MVC 3? Can this be done without using private APIs, without access to Microsoft-internal documentation and, most importantly , without having to reimplement syntax highlighting, intellisense, etc. for the embedded programming language (i.e. C# or VB)?