Col*_*nor 1 asp.net-mvc templates html-helper
我有一个模特
public class Person {
public string Name { get; set; }
public int Age { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
和一个简单的视图
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IList<Site.Models.Person>>" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body>
<% for (int i = 0 ; i < Model.Count ; i++) { %>
<%: Html.DisplayFor(m => m[i])%>
<% } %>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
部分视图
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Site.Models.Person>" %>
<h1>A person</h1>
<div>Name: <%: Html.DisplayFor(x => x.Name)%></div>
<div>Age: <%: Html.DisplayFor(x => x.Age)%></div>
Run Code Online (Sandbox Code Playgroud)
和单个控制器
public ActionResult Index () {
Person p1 = new Person { Age = 18 , Name = "jon" };
Person p2 = new Person { Age = 23 , Name = "bob" };
return View(new List<Person> { p1 , p2 });
}
Run Code Online (Sandbox Code Playgroud)
视图中的Displayfor应显示使用局部视图中指定的模板显示的每个人,但事实并非如此.谢谢你的帮助
归档时间: |
|
查看次数: |
5167 次 |
最近记录: |