http://blog.csdn.net/cheny_com/article/details/6298496
There are a lot of places to adapt from ASPX to chshtml, and this post is an update to the individual learning notes. It is programmed with this thread every day.
Sort by the first letter of a meaningful compilation error to make it easier to find:
Cannot implicitly convert type ' void ' to ' object '
Error: @Html. renderpartial ("_xxxx", Model);
Correct: @{html.renderpartial ("_xxxx", Model);}
Other: This writing profoundly shows that the code "<% xxx;%>" becomes @{xxx;
But it feels so ugly, is there a better one?
' object ': type used in a using statement must is implicitly convertible to ' system.idisposable '
Error: @using "...";
Correct: @using ...; (remove the quotation marks)
Explanation: It is possible to understand that, in addition to a more than a @, and the CS file in the same syntax.
The name ' I ' does not exist in the current context
Error:
@{
<table>
for (int i = 0; I <=; i++)
{
<tr>
//here, I
</tr>
}
</ Table>
}
is correct:
<table>
@for (int i = 0; I <=; i++)
{
<tr>
I was used here.
</tr>
}
</table>
Any <> will change from C # syntax to HTML syntax, while @{} is the opposite.
-----------------------------------------------------------------------------------------------
Not good: (can also run)
<td>
@foreach (var user in Roles.getusersinrole ((string) viewbag.oldrole))
{
<text> @user <br/></text>
</td>
Good:
<td>
@foreach (var user in Roles.getusersinrole ((string) viewbag.oldrole))
{
@user <br/>
}
</td>
Note: @ In addition to the context from HTML to CS, can also do the opposite change. The simplicity of this code is much better.
Description: I thought razor would like to "Mosaic C # in HTML" into "embedded HTML in C #" (Like Helper). The advantage of the latter is that it can be tested while the former is not. In the launch of Razor when the official website once mentioned to let Razor can test, do not know how to achieve, wait and see.
Click to download the free Agile Development textbook: The Martian Agile Development Handbook
Razor: Common mistakes and proper writing methods from aspx to cshtml