Syntax based on MVC3 Razor view engine

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

For a long time did not concern the development of Microsoft, see MVC3 today, by the way of learning, I think Razor is a good idea, than using <%%> much more simple, and the best. The first “ _” at the beginning of the cshtml document will not be able to access the server, and asp.net in the config document almost.

Razor syntax to @ beginning, wrapped in @{}, in variable using private and so on are defined and basically had no effect, so is not needed, direct var statement can. Code is case sensitive, if you use the vbhtml estimation can not distinguish, I use c# so clearly. Primary web developers like HTML and.NET and use, this will meet your needs, feel more and more. Microsoft...


Note: in the composition string @ variable string such as "xxxxxx@ixxxxxxxx" if you want to output variables in @i requires the mailto:%7B@i} package, otherwise it will parse error. This editor is too depressed will resolve Email address. The following with a master write:


2 the use of logical processing

@{
    if (xx)
    {
    //do something
    }
    else
    {
    //do anything
    }
}

3 in the internal @{...} Using HTML markers

@{
    <p>text</P>
    <div>div1</div>
}

4 in the @{...} internal output text using the @: single output:

@{
    @:This is some text
    @:This is text too
    @:@I can also be output variables
}

Use <text /> multi line output:

@{
    <text>
        tomorrow is good
        some girl is nice
    </text>
}

5 in the internal @{...} use annotations

@{
    //Single line comment
    var i = 10;
    //defg
}
 
    @* Multi line comments *@
    @* 
        Multi line comments
        Multi line comments 
    *@
 
 
@{
    @*
        Multi line comments
        Multi line comments 
    *@
    var i = 10;  @* asdfasf *@
}
 
<!-- could also use the default C#/* ... */ -->
 
@{
    /*
        Multi line comments 
    */
}

If the use of < in internal @{...};! ----> notes, will be output to the page, if in the <----> internal use! @ variables, will be processing @{

<!-- time now: @DateTime.Now.ToString() --> } Output: <!-- time now: 4/9/2011 12:01 -->

6 types of AsInt (), IsInt (AsBool), IsBool () () (), IsFloat (AsFloat) AsDecimal (AsDateTime), IsDecimal () (), IsDateTime (ToString) (example):

@{
    var i = “10”;
}
 
<p> i = @i.AsInt() </p> <!The output I = 10> 

7 the use of cycle

<!-- 1-->
@for (int i = 10; i < 11; i++)
{
    @:@i
}
<!-- 2-->
@{
    for (int i = 10; i < 11; i++)
    {
        //do something
    }
}
 
<!Similarly, --while>

At the end of her!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Cleveland at November 17, 2013 - 9:59 AM