ASP.NET MVC Razor Render Without Encoding

ASP.NET MVC Razor render without encoding

Since ASP.NET MVC 3, you can use:

@Html.Raw(myString)

ASP.NET MVC Razor render SelectList without encoding

The easiest way to achieve this in C# is to use \xA0 instead of   so you can avoid all that extra code.

Credit goes to this answer: How to retain spaces in DropDownList - ASP.net MVC Razor views

Turn off HTML Encoding in Razor

You could use the Raw() function but it's mostly meant for things that come from the database.

For a helper like you have I would suggest returning an IHtmlString:

static public IHtmlString SpeakEvil() {
return new HtmlString("<script>alert('BLAH!!');</script>");
}

That way you don't have have to call Raw() at every callsite.

How to prevent ViewData content encoding in ASP.Net Core Razor?

Resolve problem by adding to Startup.cs next code:

services.Configure<WebEncoderOptions>(options =>
{
options.TextEncoderSettings = new TextEncoderSettings(UnicodeRanges.All);
});

in ConfigureServices class.

Can an mvc razor @helper return a non-encoded tag?

You could use @Html.Raw(r) rather than just @(r).

Render razor view to string without munging the html

This is actually a bug I ran into during the summer, see bug report and response from Microsoft here bug and workaround. Good news is that according to MS it should be fixed when VS2013 is released.

Workaround is to disable the browser link feature see here browser link feature



Related Topics



Leave a reply



Submit