zoukankan      html  css  js  c++  java
  • ASP.NET MVC View层学习笔记

    1、ViewDataDictionary类是View层核心。

    2、在标记为From runt="server" 范围中可以使用 ViewData中吗?以及局部刷新(待实验验证

    3、View容易混淆的概念(View负责输出数据而非样式)。

    4、指定View输出(Return View("~/url/other/index.aspx"))。

    5、在View中使用强数据类型

    非强类型写法 (Controller & View)

    Public ActionResultList()
    {
    varproducts=new List<Product>();
    for(inti=0;i<10;i++){
    Products.add(new product{productName=“p”+i});}
    ViewData[“Products”]=products;
    return View();
    }
    <ul>
    <%foreach(Product p in(ViewData[“Products”] as Ienumerable<Product>)){%>
    <li><%: p.ProductName%></li>
    <%}%>

    强类型写法 (Controller & View)

    Public ActionResultList(){varproducts=new List<Product>();for(inti=0;i<10;i++){Products.add(new product{productName=“p”+i});}return View(products);}
    <%@ Page Language=“c#” MasterPageFile=“~/Views/Shared/Site.Master”
    Inherits=“System.Web.Mvc.ViewPage<IEnumerable<Product>>”%>
    <ul>
    <%foreach(Product p in Model){%>
    <li><%: p.ProductName%></li>
    <%}%>
    </ul>

    6、ViewModels(自定义ViewModels)

    Public class ShoppingCartViewModel
    {
    public List<Product> Products{get;set;}
    public decimal CartTotal{get;set;}
    public string Message{get;set;}
    }
    <%@ Page Language=“c#” MasterPageFile=“~/Views/Shared/Site.Master”Inherits=“System.Web.Mvc.ViewPage<IEnumerable<ShoppingCartViewModel>>”%>

    7、HtmlHelper类的与扩展方法

    ViewPage提供了一个名为Html的HtmlHelper属性;

    Using System.Web.Mvc.Html名字空间

    8、Html中的强类型

    MVC1<%:Html.TextBoxFor("PropertyName")%>

    MVC2<%:Html.TextBoxFor(m => M.PropertyName)%>

    <%: 代表Asp.NET Mvc的特征

  • 相关阅读:
    线程状态转换
    CyclicBarrier和CountDownLatch区别
    MySQL事务原理
    DownLoadManager[20530:228829] DiskImageCache: Could not resolve the absolute path of the old directory.
    App各种Icon及Launch image的尺寸和用途
    关于iPhone开发的一些建议
    iPhone6/6Plus下app状态栏内容放大问题处理
    PDF转jpg
    ios开发学习笔记
    nil和Nil和NULL的判断
  • 原文地址:https://www.cnblogs.com/cuiwenke/p/1958410.html
Copyright © 2011-2022 走看看