zoukankan      html  css  js  c++  java
  • 无废话版本-Asp.net MVC4.0 Rasor的基本用法

    最近工作有点忙,好久没写东西了!废话不多说了,进入主题!

    1.在页面中输出单一变量时候,只要在C#语句之前加上@符号即可,For example:

    <p>Now Time:@DateTime.Now</p>
    

    请注意,上述example中虽然使用C#语言撰写代码,但输出单一变量的时候,不需要加上分号;

    2.在页面上输出一段含有空白字元或者运算子的结果时,必须在前后加上一个小括号,For example:

    <p>
    UserName:@(User.Identity.Name+Model.Member)
    State        :@(ViewBag.IsEnabled?"启用":"停用")
    </p>
    

      --前台页面

    @{
        Layout = null;
    }
    @{
        var htmlAttribute = ViewData["Dictionary"] as IDictionary<string, object>;
    }
    
    <!DOCTYPE html>
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Rasor</title>
    </head>
    <body>
        <h1>Rasor基本语法</h1>
        <div>
            @using (Html.BeginForm("About", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
            {
                @Html.TextBox("Field", " ", new { type = "file", @class = "ed", size = "25" })<br />
                @Html.Password("Pwd", "", htmlAttribute)<br />
                @Html.TextBox("Email", "133030@qq.com", htmlAttribute)<br />
                @Html.Hidden("Hidden", "Value", htmlAttribute)<br />
                @Html.DropDownList("List",ViewData["List"] as SelectList,"请选择")
            }
        </div>
    </body>
    </html>
    

      

      后台方法:

    public ActionResult Rasor()
            {
                IDictionary<string, object> attr = new Dictionary<string, object>();
                attr.Add("size","32");
                attr.Add("style","color:red");
                ViewData["Dictionary"] = attr;
                //DropdwonList的用法
                List<SelectListItem> list = new List<SelectListItem>();
                list.Add(new SelectListItem { Text="中国",Value="1"});
                list.Add(new SelectListItem { Text = "美国", Value = "2" });
                list.Add(new SelectListItem { Text = "俄国", Value = "3" });
                ViewData["List"] = new SelectList(list, "Value", "Text", "");
                return View();
            }
    

      

  • 相关阅读:
    武道之路-炼体期五重天中期
    武道之路-炼体期五重天
    武道之路-炼体期四重天巅峰
    修改Oracle监听端口
    完美解决IE(IE6/IE7/IE8)不兼容HTML5标签的方法
    Create Linked Server SQL Server 2008
    Oracle:ODP.NET Managed 小试牛刀
    jquery ajax跨域请求webservice webconfig配置
    oracle 11g ORA-12541: TNS: 无监听程序 (DBD ERROR: OCIServerAttach)
    oracle 11g 一直提示 严重: 监听程序未启动或数据库服务未注册到该监听程序
  • 原文地址:https://www.cnblogs.com/alphafly/p/3925681.html
Copyright © 2011-2022 走看看