Razor练习4_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > Razor练习4

Razor练习4

 2015/5/8 11:11:43  Insus.NET  程序员俱乐部  我要评论(0)
  • 摘要:今天练习Razor的逻辑处理。一般会使用下面1.if2.else3.elseif4.switch下面演示中,Insus.NET分别演示1,2,4:xxx.cshtml代码如下:@{Layout=null;stringlaborDay="2015-05-01";stringname="Insus.NET";string[]colors={"ff0000","0000ff","00ff00"};//red,blue,green}<!DOCTYPEhtml><html><
  • 标签:

今天练习Razor的逻辑处理。一般会使用下面

1. if

2. else

3. else if

4. switch

 

下面演示中,Insus.NET分别演示1,2, 4:
xxx.cshtml代码如下:

class="code_img_closed" src="/Upload/Images/2015050811/0015B68B3C38AA5B.gif" alt="" />logs_code_hide('c9acc57b-da91-4c6b-a6fb-2bfd9d66bb1b',event)" src="/Upload/Images/2015050811/2B1B950FA3DF188F.gif" alt="" />
@{
    Layout = null;

    string laborDay = "2015-05-01";
    string name = "Insus.NET";

    string[] colors = { "ff0000", "0000ff", "00ff00" };  //red, blue, green
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <div>
        @if (laborDay.IsDateTime())
        {
            if (laborDay == "2015-05-01")
            {
                @: The day is labor day.
            }
        }

        <p><br /></p>
        @*
             @if (name == "Insus.NET")
            {
                <p>This is my name: @name.</p>
            }
            else
            {
                <p>That's not my name.</p>
            }
        *@

        @(name == "Insus.NET" ? string.Format("This is my name: {0}", @name) : "That's not my name")

        <p><br /></p>

        @foreach (string s in colors)
        {
            switch (s)
            {
                case "ff0000":
                    @: red
                    break;
                case "00ff00":
                @: green
                    break;
                case "0000ff":
                @:blue
                    break;
                default:
                @: black or white
                    break;
            }
        }

    </div>
</body>
</html>
View Code


动画演示(太约12分钟左右):



上面的练习演示中,其中有颜色写错了,参考上面的代码为准:

 

  • 相关文章
发表评论
用户名: 匿名