viewengine

Render partial view to string MVC4

ぃ、小莉子 提交于 2019-11-29 21:16:32
问题 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);

How to concisely create optional HTML attributes with razor view engine?

谁说胖子不能爱 提交于 2019-11-29 20:52:56
I'm looking for a way to write the following code with less lines of code (maybe 5). I suppose I could do the same thing as the selected class but this razor syntax isn't looking pretty. <ul> @foreach (var mi in Model.MenuItems) { <li@(mi.Selected?" class=\"selected\"":null)> @if (string.IsNullOrEmpty(mi.Title)) { <a href="@mi.Href">@mi.Text</a> } else { <a href="@mi.Href" title="@mi.Title">@mi.Text</a> } </li> } </ul> Fixed in ASP.NET MVC 4 see http://weblogs.asp.net/jgalloway/archive/2012/02/16/asp-net-4-beta-released.aspx Conditional attribute rendering If you have an attribute that might

alternative asp.net MVC view engines

会有一股神秘感。 提交于 2019-11-29 14:44:28
问题 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? 回答1: 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,

How do you declare a comment using the Razor view engine? [duplicate]

℡╲_俬逩灬. 提交于 2019-11-29 09:03:06
This question already has an answer here: Razor comment syntax 4 answers Using ASP.NET MVC's default view engine, you can declare a server-side comment like this: <%-- This is a comment --%> This comment will only be visible on the server side and is not sent to the client. How would I do the same with the Razor view engine? Start the comment block with @* , end the comment block with *@ . Similar to C# ( /* and */ ) @* single line comment *@ or @* this is a comment this is another *@ More on Razor comments on the Gu's blog . 来源: https://stackoverflow.com/questions/4467496/how-do-you-declare-a

Partials with Node.js + Express + Hogan.js

半腔热情 提交于 2019-11-28 20:33:28
I'm developing a site with Node.js + Express and using as view engine Hogan.js. This is my file app.js : /** * Module dependencies. */ var express = require('express') , routes = require('./routes') , user = require('./routes/user') , http = require('http') , path = require('path'); var app = express(); app.configure(function(){ app.set('port', process.env.PORT || 3000); app.set('views', __dirname + '/views'); app.set('view engine', 'hjs'); app.use(express.favicon()); app.use(express.logger('dev')); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.cookieParser(

What is view engine? What does it actually do?

拥有回忆 提交于 2019-11-28 18:08:26
I started learning ASP.NET MVC3. So, while reading tutorials online and in books, I came across this term "view engine" quite frequently. I don't know what it is. What does it actually do? Why should it matter to me at all? mnemosyn The view engine is responsible for creating HTML from your views. Views are usually some kind of mixup of HTML and a programming language. The pattern behind most of these is called two-step view . For example, ASP.NET comes with its own view engine out of the box. That is the one where views have lots of tags like <% %> and <%: %> . It uses the .aspx file

How to concisely create optional HTML attributes with razor view engine?

。_饼干妹妹 提交于 2019-11-28 17:02:42
问题 I'm looking for a way to write the following code with less lines of code (maybe 5). I suppose I could do the same thing as the selected class but this razor syntax isn't looking pretty. <ul> @foreach (var mi in Model.MenuItems) { <li@(mi.Selected?" class=\"selected\"":null)> @if (string.IsNullOrEmpty(mi.Title)) { <a href="@mi.Href">@mi.Text</a> } else { <a href="@mi.Href" title="@mi.Title">@mi.Text</a> } </li> } </ul> 回答1: Fixed in ASP.NET MVC 4 see http://weblogs.asp.net/jgalloway/archive

Razor Nested Layouts with Cascading Sections

不打扰是莪最后的温柔 提交于 2019-11-28 16:47:06
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 course, I can define each section in each skin. For instance, if _Common needs to call RenderSection(

How to Download Razor View Engine

扶醉桌前 提交于 2019-11-28 12:16:38
I want to download and install razor view engine for ASP.Net MVC 2. From where i can download and install? Possibly a bit outdated but you should maybe take a look at this post. http://stefan.rusek.org/Posts/Using-Razor-with-ASP-NET-MVC-in-Four-Easy-Steps/26/ Razor is capable of running standalone so it is entirely possible to provide the wiring yourself. Whether or not you need to be using .NET4 or not I am not 100% sure of. On another note MVC3 is at RC status and has a Go-Live license which emans you could technically start using now and when the RTM hits (soon) just upgrade. Utilizing

How do you declare a comment using the Razor view engine? [duplicate]

*爱你&永不变心* 提交于 2019-11-28 02:43:00
问题 This question already has answers here : Razor comment syntax (4 answers) Closed last year . Using ASP.NET MVC's default view engine, you can declare a server-side comment like this: <%-- This is a comment --%> This comment will only be visible on the server side and is not sent to the client. How would I do the same with the Razor view engine? 回答1: Start the comment block with @* , end the comment block with *@ . Similar to C# ( /* and */ ) @* single line comment *@ or @* this is a comment