Asp.Net教程,WinForm教程,Asp.Net MVC,vs2008教程,vs2010教程,Silverlight技术,源码下载,Asp.Net视频教程
全站热门标签
vs2010 Silverlight 存储过程 水晶报表 LINQ ADO.NET JavaScript DataGridView GridView AjaxPro DevExpress 面向对象 Extjs XML HTML教程 Oracle jQuery WPF MVC 分页 Office2010 GDI+ Visual C++2010 Dojo MySQL VB.NET WCF4.0 ASPxGridView WinForm textbox Sql2005 cookie Discuz!NT checkbox WCF SQL经典语句 T-SQL F# asp.net VS2008 SQL Ajax DropDownList VS2008新特性 TreeView Access Flex 页面执行时间 字符串 DataSet VB2005 回调 动画 C#时间 游戏 ASP.NET MVC
当前位置: 主页 > Mvc技术 >

在Asp.net MVC中使用Repeater控件(2)

时间:2010-08-15 22:06来源:未知 作者:admin 点击:

控制器代码:

上面的代码做了什么:


public ActionResult Index()
            ...{
                //来点测试数据
                List entities = new List();
 
                entities.Add(new RepeaterInMvc.Models.TestInfo ...{ Id = 1, Name = "Kagilo1", Email = "1@1.com" });
                entities.Add(new RepeaterInMvc.Models.TestInfo ...{ Id = 2, Name = "Kagilo2", Email = "1@1.com" });
                entities.Add(new RepeaterInMvc.Models.TestInfo ...{ Id = 3, Name = "Kagilo3", Email = "1@1.com" });
                entities.Add(new RepeaterInMvc.Models.TestInfo ...{ Id = 4, Name = "Kagilo4", Email = "1@1.com" });
                entities.Add(new RepeaterInMvc.Models.TestInfo ...{ Id = 5, Name = "Kagilo5", Email = "1@1.com" });
 
                ViewData["TestList"] = entities;
                return View();
            }
 
 
再看看页面代码:


<%@ Register Assembly="RepeaterInMvc" Namespace="RepeaterInMvc.Codes" TagPrefix="mvc" %>

    <asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
        Home Page
    </asp:Content>

    <asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
        <h2>Repeater示例</h2>
        <p>

<mvc:MvcRepeater Key="TestList" runat="server">
                <ItemTemplate>
                    <div style="height:30px; line-height:30px;"><%# Eval("Id") %>, <%# Eval("Name") %>, <%# Eval("Email") %></div>
                </ItemTemplate>
                <AlternatingItemTemplate>
                    <div style="height:30px; line-height:30px; background:#eeeeee;"><%# Eval("Id") %>, <%# Eval("Name") %>, <%# Eval("Email") %></div>
                </AlternatingItemTemplate>
            </mvc:MvcRepeater>
        </p>
    </asp:Content>
注册

<%@ Register Assembly="RepeaterInMvc" Namespace="RepeaterInMvc.Codes" TagPrefix="mvc" %>
在当前页面注册控件!!! 当然,你也可以在 web.config 中的 page/controls 节点中为所有页面注册。
 

Tags:ASP.NET MVC Repeater
责任编辑:admin
返回顶部
------分隔线----------------------------
推荐内容
骆驼户外男 真皮磨砂日常休闲鞋 低帮 2011秋冬新款 专柜正品特价 骆驼户外男 真皮磨砂日常休闲鞋 低帮 2011秋冬新款 专柜正品特价