Tracking Forums, Newsgroups, Maling Lists
Home Submit Tracker Forums
  Advanced Search


Emitting Unencoded Strings In A Razor View?

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...

View 4 Replies (Posted: Jul 28 10 at 19:41)

Sponsored Links:

Related Forum Messages For ASP.NET category:
MVC :: How To Return Unencoded HTML To A Razor View
 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? 

Posted: Sep 07, 2010 03:00 AM

View 1 Replies!   View Related
Html - Formatting Strings In .NET Razor?
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.

Posted: Jul 27 10 at 6:59

View 3 Replies!   View Related
How To Hide Specific Elements On A Razor View Based On Security Without Logic In View
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.

Posted: 2 days ago

View 1 Replies!   View Related
MVC 3 - Razor - Trying To Use A Partial View For A File Upload In A Create View?
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

Posted: Oct 19, 2010 02:06 AM

View 1 Replies!   View Related
Is It Possible To Use Razor View Engine Outside
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 in a "normal" .net environment for example to generate text, code,...

Posted: Sep 2 10 at 15:58

View 3 Replies!   View Related
MVC :: How To Translate A View To Razor
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?

Posted: Nov 15, 2010 06:10 PM

View 4 Replies!   View Related
MVC :: Get Row Count In Razor View?
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.

Posted: Feb 21, 2011 10:25 PM

View 14 Replies!   View Related
MVC :: Migrate 2 Project To 3 - Razor View
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.

Posted: Sep 08, 2010 01:40 PM

View 37 Replies!   View Related
MVC :: How To Set A Break Point In A Razor View
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?

Posted: Nov 11, 2010 08:20 PM

View 3 Replies!   View Related
MVC :: Unit Testing Razor View?
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.

Posted: Mar 03, 2011 10:15 AM

View 2 Replies!   View Related
MVC :: Unit Test Razor View In 3?
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?

Posted: Mar 11, 2011 02:32 PM

View 2 Replies!   View Related
MVC :: C# Code In Razor View - Right Statement?
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?

Posted: Feb 27, 2011 07:42 PM

View 2 Replies!   View Related
MVC :: Razor - Create Instance Of View?
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?

Posted: Oct 12, 2010 03:35 AM

View 25 Replies!   View Related
MVC :: 3 Razor Add Script From Partial View
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?

Posted: Feb 17, 2011 04:04 PM

View 3 Replies!   View Related
.net - Execute Razor View Dynamically?
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?

Posted: Feb 23 at 5:14

View 1 Replies!   View Related
Does The Razor View Engine Work For Mono
I tried searching a bit and didn't find an answer. Does the Razor View Engine work in Mono?

Posted: Nov 21 10 at 18:57

View 3 Replies!   View Related
MVC :: How To Integrate Razor View Engine Into Web Application
How to integrate Razor view engine into mvc 2 web application?

Posted: Dec 21, 2010 02:54 AM

View 3 Replies!   View Related
MVC :: Razor View Engine - 'content' From DB Using VirtualPathProvider?
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 )

Posted: Dec 14, 2010 12:25 AM

View 1 Replies!   View Related
MVC :: Razor View Engine And Add Namespace In Web.Config
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?

Posted: Aug 22, 2010 02:21 AM

View 4 Replies!   View Related
MVC :: How To Show Razor View In J Query Light Box
How to show Razor View in J Query Light box give me a full example.

Posted: Mar 26, 2011 10:36 AM

View 10 Replies!   View Related
MVC :: Changing The View Folder Structure With Razor?
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


Posted: Nov 18, 2010 07:41 PM

View 1 Replies!   View Related
How To Import A Namespace In Razor View Page
How to import a namespace in Razor View Page?

Posted: Jul 13 10 at 16:03

View 3 Replies!   View Related
Html.CheckBoxFor In VB Razor View - Right Statement?
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?

Posted: Feb 27 at 20:37

View 2 Replies!   View Related
Base Class Of Razor View In ASP MVC3
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.

Posted: Oct 18 10 at 22:14

View 1 Replies!   View Related
MVC :: Can't View Intellisense On Razor And Visual Studio
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?

Posted: Aug 22, 2010 02:11 AM

View 3 Replies!   View Related
MVC :: Get The Data From Join Tables In The View (Razor)?
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...

Posted: Mar 05, 2011 10:01 PM

View 2 Replies!   View Related
Rendering Telerik MVC Grid In A Razor View?
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);

Posted: Dec 16 10 at 8:33

View 1 Replies!   View Related
MVC :: Does The Razor View Engine Support Generic Methods
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.

Posted: Sep 03, 2010 07:26 PM

View 2 Replies!   View Related
Razor View Engine Intellisense Not Working VS 2010?
Inside VS 2010 I do not have any intellisense working. I have reinstalled everything and still nothing is coming up for intellisense?

Posted: Feb 7 at 19:34

View 2 Replies!   View Related
Installing The Razor View Engine For Visual Studio?
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?

Posted: Jul 14 10 at 23:37

View 4 Replies!   View Related
MVC :: Changing View Engine In Existing Project To Razor?
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 ..."

Posted: Nov 15, 2010 03:57 PM

View 2 Replies!   View Related
MVC :: Razor View - Datetimpicker For All Date Time Fields?
How do I go about having a new razor editortemplate for a datepicker, preferabbly jqueryUi in MVC 3?

Posted: Feb 10, 2011 07:51 PM

View 22 Replies!   View Related
MVC :: Can't Get Razor List View Headings To Use Model Properties
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.

Posted: Mar 30, 2011 11:33 PM

View 2 Replies!   View Related
Visual Studio :: See The Razor Code In A Design View?
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.

Posted: Feb 05, 2011 10:35 PM

View 1 Replies!   View Related
MVC :: Razor View Engine - How To Register The Partial Views In 3 Beta
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?

Posted: Oct 15, 2010 07:10 PM

View 1 Replies!   View Related
MVC :: Unable To Add Working Form Inside A Section Of Razor View
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.

Posted: Feb 16, 2011 03:32 AM

View 5 Replies!   View Related
MVC :: Razor: Strongly Typed View With Model Containing Collection Properties?
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.

Posted: Jan 04, 2011 11:50 PM

View 1 Replies!   View Related
MVC 3 Razor Syntax - Partial View Menu.cshtml With Full Markup
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?

Posted: Mar 27 at 16:36

View 2 Replies!   View Related
How To Use Razor View Engine Auto-complete To Work In A Class Library
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:


Posted: Nov 11 10 at 19:42

View 3 Replies!   View Related
Copyright © 2005-08, All rights reserved