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列表进行绑定的。

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

  • 相关阅读:
    el自定义函数库
    DOM4J
    【转载】SqlServer日期时间函数
    【原创】C#认识/理解/运用 StreamReader,StreamWriter,StringReader,StreamWriter
    【原创】C#认识/理解/运用 FileStream
    【原创】C#操作XML(带命名空间)
    【原创】ASP.NET MVC3使用html编辑器(kindeditor)
    【原创】ASP.NET MVC3 从零开始一步步构建Web
    【转载】MVC使用jqGrid
    【原创】C#使用HttpWebRequest,HttpWebResponse
  • 原文地址:https://www.cnblogs.com/lmfeng/p/2038158.html
Copyright © 2011-2022 走看看