zoukankan      html  css  js  c++  java
  • asp net mvc 的数据绑定

    数据绑定方式1: ViewData.Add("documentRead", new
                        {
                            DocumentID = documentInfo.DocumentID,
                            documentInfo.CategoryID,
                            documentTitle = documentInfo.GetLangInfo(DefaultLanage).DocumentTitle,
                            Description = documentInfo.GetLangInfo(DefaultLanage).Description,
                            Author = documentInfo.GetLangInfo(DefaultLanage).Author,
                            UserID = documentInfo.UserID,
                            Keywords = SearchKeywords(documentInfo.DocumentID),
                            documentURL = GetURL(documentInfo.DocumentID),
                            DownloadCount = documentInfo.DownloadCount,
                        })

    这里的code是在控制里面绑定数据,然后可以在aspx页面里面调用documentRead中的DocumentID、CategoryID、documentTitle......等等这些属性,

    在aspx页面里面的写法是:<%= ViewData.Eval("documentRead.Keywords")%>,这样就绑定了documentRead中的Keywords的属性

    数据绑定方式2:ViewData["dclist"] = listDocument.Select(c => new
                       {
                         c.DocumentID,
                         DocumentName = c.GetLangInfo(DefaultLanage).DocumentTitle,
                         DocumentURL = GetURL(c.DocumentID),
                      })

    这里的code是在控制里面绑定数据,然后可以在aspx页面里面调用dclist中的DocumentID、DocumentName、DocumentURL这些属性,

    在aspx页面里面的写法是:<%# Eval("DocumentURL")%>,这样就绑定了dclist中的DocumentURL的属性,

    上面这两种绑定的方式有点相识,不过要注意区分,各自的功能也不是一样的。

    数据绑定方式1是对一个documentInfo对象进行进行绑定的,数据绑定方式2是对一个listDocument列表进行绑定的。

    先慢慢体会一下,以后再来更加复杂的绑定。。

  • 相关阅读:
    python 包管理工具 pip 的配置
    Python 变量作用域 LEGB (下)—— Enclosing function locals
    Python 变量作用域 LEGB (上)—— Local,Global,Builtin
    2020 Java 面试题 小结 (答案慢慢补上,有错误请指出)
    mysql 根据日期(date)做年,月,日分组统计查询
    jvm指令
    正则表达式 分割地址 获取省市区详细地址
    .Net 异常记录
    WCF设计服务协议(一)
    plsql ORA-01789:查询块具有不正确的结果列数
  • 原文地址:https://www.cnblogs.com/lmfeng/p/2038158.html
Copyright © 2011-2022 走看看