WebMatrix :: Razor Needs Shorter Syntax To Prevent HTML Encoding?
Oct 27, 2010
It's great that Razor HTML encodes by default. However, many times I have HTML in a database and want to display it literally on a page. In WebForms 4, we can use <%= %> and <%: %> to choose between encoding options. Raven's syntax is currently @(new HtmlString(Model.Greeting)).
add a shorter syntax to Razor. Something like @=Model.Greeting or @@Model.Greeting, or something else.
In Windows Forms I can create a class file called 'Authentication.cs' with the following code:
public class Authentication { public string Name; internal bool Authenticate() { bool i = false; if (Name == "Jason") { i = true; } return i; } }
In WebMatrix, I can insert a new Class file, called 'Authentication.cs', and insert the above code. And in my default.cshtml file, I do this:.........................
I'm just starting out with WebMatrix and would like to know how to style a @Html.TextBox("email") and @Html.Password("password") control? I've tried (in my CSS file):
.email{ /* styles here */ } .password{ /* styles here */ }
But that has no effect at all. How can we style these types of controls?
While it has gnerally been advocated to separate code from mark up and all that, with the razor syntax and webmatrix all that is not valid anymore, I think. WebMatrix encourages code and mark up in the same page! So what is the best practice as far as code and mark up is concerned.
Check out the following: <a href="/test?x=@if (Model.IsTest) { @(1) } else { @(4) }"></a> Is there a better way to write this instead of the @(1) and @(4)?
I have a GridView bound to a DataTable that I construct. Most columns in the table contain the raw HTML for a hypelinklink, and I would like that HTML to render as a link in the browser, but the GridView is automatically encoding the HTML, so it renders as markup.
How can I avoid this without explicitly adding HyperLink, or any other, columns?
My hosting company states they support .net and razor. However after uploading my website made with webmatrix and razor *.cshtml pages. When i visit my website all i get is 404.17 error messages. As an testcase i decided to add an standard .aspx page. Visiting that page gives the same 404.17 error message :-( .
According to my webhoster my web.config is wrong. However that one is generated by webmatrix. Besides my *.cshtml *.aspx a lot of files and directories are added to the bin folder. What can i check and what should my hosting provider check. When using the check compatibility the asp.net version is shown as unknown? My hosting provider claims my site is running asp.net 4.0 in integrated mode and that should be enough.
For reporting we used report RDLCs and displayed using an ASPX form. We implemented using the route as shown below. This resulted in forcing us to use the page route below and also to use the hyperlink instead of the normal Action Link. The question is how do we convert the asp:hyperlink ASPX syntax to Razor syntax.
the new VS 2010 features mentions "the new <%: %> encoding syntax". What does it do? Searching for these tags with Google doesn't seem to be possible...
How would I retrieve IP address with Razor? I have tried @Request.UserHostAddress and it returned ::1 to me instead of an IP adress. I am running this of course under IIS8 that came with webmatrix.
How can I stop ASP.Net from encoding anchor tags in List Items when the page renders?I have a collection of objects. Each object has a link property. I did a foreach and tried to output the links in a BulletedList, but ASP encoded all the links.Here's the offending snippet of code. When the user picks a specialty, I use the SelectedIndexChange event to clear and add links to the BulletedList:
if (SpecialtyList.SelectedIndex > 0) { PhysicianLinks.Items.Clear();
I'm learning razor syntax, using the startersite in WebMatrix and trying to display some data from a table. I want to select only the data from the logged in user, so in effect want to say
...WHERE UserId =@WebSecurity.CurrentUserId";but that doesn't work.
Using the @0 method doesn't work for me either - I get an 'A parameter is missing. [ Parameter ordinal = 1 ]' error.
Do I have to set a variable then use the @0 / @1 / @whichever way? If so - what's wrong with this code?
@{ //Is the user logged in? WebSecurity.RequireAuthenticatedUser(); [code]...
How does one create a .cshtml page in an ASP.NET web application? The option to choose Razor is obvious when using MVC - it appears when adding a view. But I can't seem to figure out how to accomplish this in a plain ASP.NET Web Application. Is it even possible?
When you do introduce intellisense and colorization to the razor editor, what about allowing the developer to choose the schema that it verifies against? If it could by default use a flavour of HTML, but optionally allow the dev to reference an arbitary XSD file (as supportted by the XML text editor). It could result in a very flexible experience that supports using ASP.Net MVC as a web service returning XML.