I am using MVC3 framework to design a website. I pull the data in the controller from the ms sql database and one of the columns in the table is named as “do”. When I try to create a view to display the information using the @Model keyword (eg: @Model.do) , I get an error:
Identifier expected; do is a keyword.
I want to know if there is a way to use the column names ( which are keywords in c#) in the MVC3 views or do I only have the choice of renaming the column in the database table ?
Thank You !!
The way you use any keyword in C# is to prefix it with an ‘@’. For example, you’ll see this a lot
to add “class” attribute to a “a” tag. This is legitimate code:
and so is
If you are using ASPX as your view engine, the following is fine:
In Razor view, the following is also valid:
or