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

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

  • 相关阅读:
    Android--将图片存放到我们本地
    Android--将Bitmip转化成字符串
    Android--启动系统的剪切图像功能并返回结果
    Android--从相册中选取照片并返回结果
    Android--启动拍照功能并返回结果
    Android--PullToRefreshListView的onRefreshComplete()不起作用的问题
    Android判断当前的android设备是否处于联网状态
    Android中修改状态栏的颜色和我们App的风格一致
    ListView的多布局中的小问题
    [Android] Activity间切换,传递数据
  • 原文地址:https://www.cnblogs.com/lmfeng/p/2038158.html
Copyright © 2011-2022 走看看