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

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

  • 相关阅读:
    四则运算生成器
    学习进度总结
    大三寒假实习内容
    构建之法一二章读后感
    构建之法第三章读后感
    关于NopCommerce3.6版用户登录详解
    关于NopCommerce3.6版的@Html.Widget(“home_page_top”)的说明
    Java学习心得(2)
    Java学习心得(5)
    Java学习心得(6)
  • 原文地址:https://www.cnblogs.com/lmfeng/p/2038158.html
Copyright © 2011-2022 走看看