Emitting Unencoded Strings In A Razor View?

Jul 28 10 at 19:41

As ScottGu says in his blog post «by default content emitted using a @ block is automatically HTML encoded to better protect against XSS attack scenarios». My question is: how can you output a non-HTML-encoded string?

For the sake of simplicity, pls stick to this simple case:

var html = "<a href='#'>Click me</a>"
// I want to emit the previous string as pure HTML code...


MVC :: How To Return Unencoded HTML To A Razor View

Sep 07, 2010 03:00 AM

HtmlHelperExtensions in MVC2 return a HTML string, unencoded.

In MVC3 this string is encoded! How can I return unencoded HTML to a Razor view in MVC3?

View 1 Replies View Related

Html - Formatting Strings In .NET Razor?

Jul 27 10 at 6:59

I am currently writing a small templating system in ASP.NET to allow users to add content. For example, the user can enter the string (variable type is string).

topHeader[x] = "They think it's all over. It is now!";

However, one change that's needed is the ability to add some basic HTML tags within this content, so the following can be done

topHeader[x] = "They think it's all over. <strong>It is now!</strong>" or

topHeader[x] = "They think it's all over. <a title="Football News" href="URL">It is now!</a>";

If you add such things into strings now they are not formatted as HTML, but I want to somehow escape them so that they can be. Naturally I've looked on the Internet for the answer, but as Razor is fairly new there's not much out there to help me out.

View 3 Replies View Related

How To Hide Specific Elements On A Razor View Based On Security Without Logic In View

2 days ago

I have looked all over for elegant solutions to this not so age-old question. How can I lock down form elements within an ASP.Net MVC View, without adding if...then logic all over the place? Ideally the BaseController, either from OnAuthorization, or OnResultExecultion, would check the rendering form elements and hide/not render them based on role and scope. Another approach I have considered is writing some sort of custom attributes, so as to stay consistent with how how we lock down ActionResults with [Authorize]. Is this even possible without passing a list of hidden objects to the view and putting if's all over? Other background info: We will have a database that will tell us at execution time (based on user role/scope) what elements will be hidden. We are using MVC3 with Razor Viewengine. We're utilizing a BaseController where any of the Controller methods can be overridden.

View 1 Replies View Related

MVC 3 - Razor - Trying To Use A Partial View For A File Upload In A Create View?

Oct 19, 2010 02:06 AM

I am trying to use a partial view for a file upload in a Create View.

Here is my partial view, I removed the submit button, as the view it is rendered in, should activat the form post:

@model dynamic

View 1 Replies View Related

Is It Possible To Use Razor View Engine Outside

Sep 2 10 at 15:58

If I look at the Razor View Engine, then I see a very nice and concise syntax that is not particularly tied to generating html. So I wonder, how easy would it be to use the engine outside asp.net in a "normal" .net environment for example to generate text, code,...

View 3 Replies View Related

MVC :: How To Translate A View To Razor

Nov 15, 2010 06:10 PM

I want to change my project to use razor syntax. How do I translate a view to razor syntax?

also, when I add a new view, I don't see an option for the view engine to use. Is there one?

View 4 Replies View Related

MVC :: Get Row Count In Razor View?

Feb 21, 2011 10:25 PM

I have a Razor view of type Joke. Here is the relationship between the Entity Joke and the Entity Rating:

I have done eager loading in my HomeController to get the Ratings from the Database. But I seem to be unable to get a count of the ratings that belong to a particular joke. Here is the error I get:

PS. You can ignore that <img> code to the right.

View 14 Replies View Related

MVC :: Migrate 2 Project To 3 - Razor View

Sep 08, 2010 01:40 PM

I have an application which has been built in MVC 2.0. I need to upgrade it to MVC 3.0 and that too by using Razor CSHTML engine. All the information which I got on the net was for MVC 3.0 Webform engine but nothing much for migrating to Razor.

View 37 Replies View Related

MVC :: How To Set A Break Point In A Razor View

Nov 11, 2010 08:20 PM

I can't seem to figure out how to set a breakpoint in a Razor view. I understand why that might seem a little weird and may be difficult since a cshtml file is a combination of html and then c# code, but I can step into it. The ability to step into it makes it seem like I should be able to set a breakpoint. Am I missing how to do this or is this not possible in the RC? If not any plans to add this before RTM or in the future?

View 3 Replies View Related

MVC :: Unit Testing Razor View?

Mar 03, 2011 10:15 AM

How can I render a razor view in a Unit Test?When I change for instance a html helper method, I sometimes forget to update all the views which uses that html method. So the view I forgot generates a YSOD.I would like to create unit tests that renders a view and fails if I forgot to make the neccecary updates.

View 2 Replies View Related

MVC :: Unit Test Razor View In 3?

Mar 11, 2011 02:32 PM

Is it possible to write unit tests against razor view in MVC 3? If yes, can anyone point me to code sample to unit test a razor view in MVC 3?

View 2 Replies View Related

MVC :: C# Code In Razor View - Right Statement?

Feb 27, 2011 07:42 PM

I have this C# code in a Razor view:

@(Html.CheckBoxFor<RazorSamplesWeb.Models.SamplesModel>(i => i.IsActive))

I tried translating it to this:

@Code Html.CheckBoxFor(Of RazorSamplesWeb.Models.SamplesModel)(Function(i) i.IsActive)End Code

But it's complaining. Why, and what is the right statement?

View 2 Replies View Related

MVC :: Razor - Create Instance Of View?

Oct 12, 2010 03:35 AM

In my controller method, I'm trying to create an instance of a View (cshtml file) before I wrap it around an ActionResult and return it.Since there is no "class" for Razor Views to speak off, how does one go about creating an instance of a Razor View?

View 25 Replies View Related

MVC :: 3 Razor Add Script From Partial View

Feb 17, 2011 04:04 PM

What is the best way to add javascript at runtime from a view (or partialview)? For example i would like to build a partial view Banner.cshtml that use Banner.Js. Actually i am using a section into layout page but obviusly if i use 3 times the same partial view i have 3 reference to external Js. Is there a "best practice" to include Js from "child" elemnts like partial view in this case?

View 3 Replies View Related

.net - Execute Razor View Dynamically?

Feb 23 at 5:14

is there a way to execute a razor view dynamically? if i have the view code as a string can i execute it and pass it a model as a parameter for example?

View 1 Replies View Related

Does The Razor View Engine Work For Mono

Nov 21 10 at 18:57

I tried searching a bit and didn't find an answer. Does the Razor View Engine work in Mono?

View 3 Replies View Related

MVC :: How To Integrate Razor View Engine Into Web Application

Dec 21, 2010 02:54 AM

How to integrate Razor view engine into mvc 2 web application?

View 3 Replies View Related

MVC :: Razor View Engine - 'content' From DB Using VirtualPathProvider?

Dec 14, 2010 12:25 AM

I'm working trying to realize a requirement where the pages should be 'configurable' at runtime (per client), stored in a database - a requirement that I have no say in Anyway, the current plan is to use the Razor view engine and 'load' the 'pages' dynamically. I have a basic sample working using a VirtualPathProvider and VirtualFile that serves up Raz'pages' on the fly.The question I have if there is a better approach when I have the Razor 'pages' stored in a dB (or any other repository)?

There seems to be some constraints and concerns when I check other postings. For example:'If a Web site is precompiled for deployment, content provided by a VirtualPathProvider instance is not compiled, and noVirtualPathProvider instances are used by the precompiled site.'
(from http://msdn.microsoft.com/en-us/library/system.web.hosting.virtualpathprovider.aspx )

View 1 Replies View Related

MVC :: Razor View Engine And Add Namespace In Web.Config

Aug 22, 2010 02:21 AM

I am working on a MVC project with Razor view engine and I have the following:


This only works if I have on the same view the following:


So if "SquishIt.Framework" namespace is added on Web.Config why do I need to have the @using on the view?

View 4 Replies View Related

MVC :: How To Show Razor View In J Query Light Box

Mar 26, 2011 10:36 AM

How to show Razor View in J Query Light box give me a full example.

View 10 Replies View Related

MVC :: Changing The View Folder Structure With Razor?

Nov 18, 2010 07:41 PM

I want to modify the way the Views are organised in my project to allow for a custom way of handling Globalization

I want to have an extra route param containing the country code and to pass this down to the view engine so that the correct view is displayed.

My mapRoute rule in Global.asax is set up like this...


So I want to just have 1 controller called main and then have my view folders organised like this..../Views/Main/en/Index.cshtml/Views/Main/fr/Index.cshtml I have tried creating a custom view engine but i don't know how to access the countrycode route value because none of the examples show how to do this.

Here is my attempt at a custom Razor View Engine


View 1 Replies View Related

How To Import A Namespace In Razor View Page

Jul 13 10 at 16:03

How to import a namespace in Razor View Page?

View 3 Replies View Related

Html.CheckBoxFor In VB Razor View - Right Statement?

Feb 27 at 20:37

I have this C# code in a Razor view:

@(Html.CheckBoxFor<RazorSamplesWeb.Models.SamplesModel>(i => i.IsActive))

I tried translating it to this:

@Code Html.CheckBoxFor(Of RazorSamplesWeb.Models.SamplesModel)(Function(i) i.IsActive)End Code

But it's complaining. Why, and what is the right statement?

View 2 Replies View Related

Base Class Of Razor View In ASP MVC3

Oct 18 10 at 22:14

I'm trying to have all my views inherit from a custom class so that I can add certain behaviour and values to all pages, but I'm having some issues. I tried subclassing System.Web.Mvc.WebViewPage but I'm forced to implement an Execute procedure that I don't know what it should do. Also, if I try to access the Context variable, I get a null reference (really weird). This leads me to think that I may have the wrong base class.

View 1 Replies View Related

MVC :: Can't View Intellisense On Razor And Visual Studio

Aug 22, 2010 02:11 AM

I am using VS 2010 with MVC3 and Razor view engine but on the views when I write @... I never have intellisense. Do I need to do something?

View 3 Replies View Related

MVC :: Get The Data From Join Tables In The View (Razor)?

Mar 05, 2011 10:01 PM

I have two tables: Projects and ProjectsData and I want to execute query with join and get the result in the View.

In the Controller I have this code:


What I should use in the View to extract this data. I tried that:


but it doesn't work...

View 2 Replies View Related

Rendering Telerik MVC Grid In A Razor View?

Dec 16 10 at 8:33

I have the following markup in a 'content' page. Without the Render call, nothing renders, and with the Render call, the grid renders as the first element in the whole page, not inside the 'content' section defined by my view:

@using Telerik.Web.Mvc.UI
@model Outdoor.Mvc.ViewModels.OutdoorSite.SiteList
Html.Telerik().Grid(Model.ItemList).Name("Site Grid")
.Columns(columns =>
columns.Bound(o => o.SiteId);
columns.Bound(o => o.Name);

View 1 Replies View Related

MVC :: Does The Razor View Engine Support Generic Methods

Sep 03, 2010 07:26 PM

Trying out the Razor view engine and for some reason my generic helper methods are breaking. For example:

public static class UrlHelperExtensions
public static string NonGenericHelper(this UrlHelper helper, Type controller)
return controller.Name;
public static string GenericHelper<TController>(this UrlHelper helper)
return typeof(TController).Name;

Works as expected:@Url.NonGenericHelper(typeof(ProjectEuler.UI.Models.Home))Breaks with the following exception:

"CS1502: The best overloaded method match for 'Microsoft.WebPages.WebPageUltimateBase.Write(Microsoft.WebPages.Helpers.HelperResult)'
has some invalid arguments"

The only workaround I could find is treating it as a "multi-token


Not sure if this is the intended behavior or just a bug but it would be nice to be able to call a generic method as you would a non generic one.

View 2 Replies View Related

Razor View Engine Intellisense Not Working VS 2010?

Feb 7 at 19:34

Inside VS 2010 I do not have any intellisense working. I have reinstalled everything and still nothing is coming up for intellisense?

View 2 Replies View Related

Installing The Razor View Engine For Visual Studio?

Jul 14 10 at 23:37

I just downloaded and installed Web Matrix beta.

I am really liking the razor view engine.

Not so much the Web Matrix IDE.

Is there any way to install razor view engine for use in the Visual Studio without installing WebMatrix?

View 4 Replies View Related

MVC :: Changing View Engine In Existing Project To Razor?

Nov 15, 2010 03:57 PM

how do I change the view engine from aspx to razor in an existing project? If I just change the file extension to cshtml I always get "The controller for path '/path/About' was not found or does ..."

View 2 Replies View Related

MVC :: Razor View - Datetimpicker For All Date Time Fields?

Feb 10, 2011 07:51 PM

How do I go about having a new razor editortemplate for a datepicker, preferabbly jqueryUi in MVC 3?

View 22 Replies View Related

MVC :: Can't Get Razor List View Headings To Use Model Properties

Mar 30, 2011 11:33 PM

When it creates a view using the list scaffold the headings are hard coded. I want to pull the headings from the data model, but no luck. I was assuming LabelFor would be the solution. I must be missing something basic.

View 2 Replies View Related

Visual Studio :: See The Razor Code In A Design View?

Feb 05, 2011 10:35 PM

I have a Razor coded view with extension .cshtml. I would like to see it in a design view, so I could put some controls from a tool box.

I am using Visual Studio Express.

View 1 Replies View Related

MVC :: Razor View Engine - How To Register The Partial Views In 3 Beta

Oct 15, 2010 07:10 PM

On my projects I am using Razor View engine and I need to define custom Partial folders:


I had this because there was a problem in MVC 3 Preview. Was it corrected?

How should I register the Partial Views in MVC 3 Beta?

View 1 Replies View Related

MVC :: Unable To Add Working Form Inside A Section Of Razor View

Feb 16, 2011 03:32 AM

In one of my view, I have a postback form


Now, As you can see, I have added this form inside MainBar section. Whenever I try to click on PostReply button, nothing happens.

View 5 Replies View Related

MVC :: Razor: Strongly Typed View With Model Containing Collection Properties?

Jan 04, 2011 11:50 PM

Note: I'm working with MVC3 RC and Razor views.I've got this model:


I want to have a strongly typed create view for this model, that allows you to insert 1 to many addresses and phone numbers as part of the view. Ideally, the Action is strongly typed as well:


What would this view look like to facilitate creating 1 to many Addresses and PhoneNumbers, as well as having the state re-created correctly if the ModelState fails when posting? I've tried a number of variations including EditorTemplates and can't figure out how to do this.

View 1 Replies View Related

MVC 3 Razor Syntax - Partial View Menu.cshtml With Full Markup

Mar 27 at 16:36

This question appear when I worked with partial view (MVC3/Razor), but I am sure - it's clear Razor Syntax question, not related direct to partial view. So - I have partial view Menu.cshtml with full markup as:

@model IEnumerable<SportsStore.WebUI.Models.NavLink>
@foreach(var link in Model)
@Html.RouteLink(link.Text, link.RouteValues);

No problem - "parent" view call it @{Html.RenderAction("Menu", "Nav");} and all work as magic.
But, if I will edit the Menu.cshtml as:

@model IEnumerable<SportsStore.WebUI.Models.NavLink>
@foreach(var link in Model)
Html.RouteLink(link.Text, link.RouteValues);

(see - NO '@' before Html.RouteLink!) all just broke: now @{Html.RenderAction("Menu", "Nav");} output is totally empty, no one HTML tag. Want to know - what is the difference between two piece of code? I assume @ before foreach also automatically "drop into" and apply to Html.RouteLink as well? So - am I wrong?

View 2 Replies View Related

How To Use Razor View Engine Auto-complete To Work In A Class Library

Nov 11 10 at 19:42

We have a modular architecture where we have some views (cshtml) files in a separate project (class library). How can we get the syntax highlighting and autocomplete to work when the project isn't an MVC project?

note that the class library has controllers, views, models etc. It just doesn't have the web.config, global.asax, etc that a normal mvc project would have.

The intellisense works for everything but the so important model:

With MVC3 RTM, if you hover over the Model, you can now get a better error message:


Then after adding the build provider, this error message appears:


View 3 Replies View Related

Copyrights 2005-14 www.BigResource.com, All rights reserved