zoukankan      html  css  js  c++  java
  • MVC简单笔记

    1】基本语法@{    int num1 =10;
        int num2 =5;
        int sum = num1 + num2;
        @sum;
        @(num1 +num2);
        string color ="Red";
        <font color="@color">@sum</font>
    }

    2】特殊语法
        输出@符号:@@
        输出Email地址:Razor模板会自动识别出Email地址,所以不需要我们进行任何的转换。而在代码块中,只需要使用 @:Tom@gmail.com 即可。@:表示后面的内容为文本。
        输出HTML代码(包含标签):直接输出,string html = "<font color='red'>文本</font>"; @html
        输出HTML内容(不包含标签):有两种方法,第一种:IHtmlString html=new HtmlString("<font color='red'>文本</font>"); @html; 第二种:string html = "<font color='red'>文本</font>"; @Html.Raw(html);

    3】输出列表@foreach (var p in Model) {
        <div class="item">
            <h3>@p.Name</h3>
            @p.Description
            <h4>@p.Price.ToString("c")</h4>
        </div>
    }

    4】输出用户控件@foreach (var p in Model.Products) {
        Html.RenderPartial("ProductSummary", p);
    }

    5】在controller中引用用户控件需要传递数据时,可以使用下列方法
    public ViewResult Summary(Cart cart) {
        return View(cart);
    }
    输出时: @{Html.RenderAction("Summary", "Cart");}
    public PartialViewResult Menu() {
        IEnumerable<string> categories = repository.Products
                .Select(x => x.Category)
                .Distinct()
                .OrderBy(x => x);
        return PartialView(categories);
    }
    输出时: @{ Html.RenderAction("Menu", "Nav"); }
  • 相关阅读:
    css3——box-sizing属性
    HTML5存储--离线存储
    微信公众号爆出前端安全漏洞
    Js获取宽高度的归纳集锦总结
    Yii 2 修改 URL 模式为 PATH 模式,并隐藏index.php
    SQL 查询优化 索引优化
    linux提示语言包
    安装linux工作环境
    linux常用命令
    PHP解决抢购、秒杀、抢楼、抽奖等阻塞式高并发库存防控超量的思路方法
  • 原文地址:https://www.cnblogs.com/bober/p/2718829.html
Copyright © 2011-2022 走看看