看了老赵的MVC课程(27):辅助普通Web应用程序开发(三)——Model Binder,编译不通过,稍加了修改
在webcast里实在找不出这一讲的源代码,无奈之下,自己动手稍作了一下修改.这样能编译,也能按规矩运行了.源代码下载:PartialViewTest.rar
先来看一下文档的位置,我比较懒,直接帖图比较方便:
然后,我把自己的代码帖出来,不管这么多了,从上往下帖:
首先是HomeController.cs,因为我就是用这个HomeController来做的.
接下来,是我的Models里的一个用户类UserInfo.cs:
接下来,是几个View的文件,包括那些在View里的Model文件:
Index.aspx:
IndexModel.cs:
唉呀,真多,幸好这只是一个测试的东西.
IndexUserRow.ascx:
IndexUserRowModel.cs:
在Site.css最后加了
.even
{
color:#000;
}
.odd
{
color:#f00;
}
好了,以上是我全部代码,不正确的地方,请指正.
先来看一下文档的位置,我比较懒,直接帖图比较方便:
然后,我把自己的代码帖出来,不管这么多了,从上往下帖:
首先是HomeController.cs,因为我就是用这个HomeController来做的.
Code
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.Mvc;
6using PartialViewTest.Views.Home;
7using PartialViewTest.Models;
8
9namespace PartialViewTest.Controllers
10{
11 [HandleError]
12 public class HomeController : Controller
13 {
14 public ActionResult Index()
15 {
16 List<UserInfo> userInfo = new List<UserInfo>() {
17 new UserInfo{UserId = 0,UserName = "张一",Age = 20, Sex = "男",Email = "aklsdf@163.com"},
18 new UserInfo{UserId = 1,UserName = "李二",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
19 new UserInfo{UserId = 2,UserName = "李三",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
20 new UserInfo{UserId = 3,UserName = "张四",Age = 20, Sex = "男",Email = "aklsdf@163.com"},
21 new UserInfo{UserId = 4,UserName = "李五",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
22 new UserInfo{UserId = 5,UserName = "李六",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
23 new UserInfo{UserId = 6,UserName = "张七",Age = 20, Sex = "男",Email = "aklsdf@163.com"},
24 new UserInfo{UserId = 7,UserName = "李八",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
25 new UserInfo{UserId = 8,UserName = "李九",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
26 new UserInfo{UserId = 9,UserName = "张十",Age = 20, Sex = "男",Email = "aklsdf@163.com"}
27 };
28 return View(new IndexModel(userInfo,6,2,100));
29 }
30
31 public ActionResult List(int page)
32 {
33 List<UserInfo> userInfo = new List<UserInfo>() {
34 new UserInfo{UserId = page,UserName = "张一",Age = 20, Sex = "男",Email = "aklsdf@163.com"},
35 new UserInfo{UserId = 1,UserName = "李二",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
36 new UserInfo{UserId = 2,UserName = "李三",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
37 new UserInfo{UserId = 3,UserName = "张四",Age = 20, Sex = "男",Email = "aklsdf@163.com"},
38 new UserInfo{UserId = 4,UserName = "李五",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
39 new UserInfo{UserId = 5,UserName = "李六",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
40 new UserInfo{UserId = 6,UserName = "张七",Age = 20, Sex = "男",Email = "aklsdf@163.com"},
41 new UserInfo{UserId = 7,UserName = "李八",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
42 new UserInfo{UserId = 8,UserName = "李九",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
43 new UserInfo{UserId = 9,UserName = "张十",Age = 20, Sex = "男",Email = "aklsdf@163.com"}
44 };
45 //ViewData["Message"] = "Welcome to ASP.NET MVC!";
46
47 return View(new IndexModel(userInfo, 6, page, 100));
48 }
49
50 public ActionResult About()
51 {
52 return View();
53 }
54 }
55}
56
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.Mvc;
6using PartialViewTest.Views.Home;
7using PartialViewTest.Models;
8
9namespace PartialViewTest.Controllers
10{
11 [HandleError]
12 public class HomeController : Controller
13 {
14 public ActionResult Index()
15 {
16 List<UserInfo> userInfo = new List<UserInfo>() {
17 new UserInfo{UserId = 0,UserName = "张一",Age = 20, Sex = "男",Email = "aklsdf@163.com"},
18 new UserInfo{UserId = 1,UserName = "李二",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
19 new UserInfo{UserId = 2,UserName = "李三",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
20 new UserInfo{UserId = 3,UserName = "张四",Age = 20, Sex = "男",Email = "aklsdf@163.com"},
21 new UserInfo{UserId = 4,UserName = "李五",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
22 new UserInfo{UserId = 5,UserName = "李六",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
23 new UserInfo{UserId = 6,UserName = "张七",Age = 20, Sex = "男",Email = "aklsdf@163.com"},
24 new UserInfo{UserId = 7,UserName = "李八",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
25 new UserInfo{UserId = 8,UserName = "李九",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
26 new UserInfo{UserId = 9,UserName = "张十",Age = 20, Sex = "男",Email = "aklsdf@163.com"}
27 };
28 return View(new IndexModel(userInfo,6,2,100));
29 }
30
31 public ActionResult List(int page)
32 {
33 List<UserInfo> userInfo = new List<UserInfo>() {
34 new UserInfo{UserId = page,UserName = "张一",Age = 20, Sex = "男",Email = "aklsdf@163.com"},
35 new UserInfo{UserId = 1,UserName = "李二",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
36 new UserInfo{UserId = 2,UserName = "李三",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
37 new UserInfo{UserId = 3,UserName = "张四",Age = 20, Sex = "男",Email = "aklsdf@163.com"},
38 new UserInfo{UserId = 4,UserName = "李五",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
39 new UserInfo{UserId = 5,UserName = "李六",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
40 new UserInfo{UserId = 6,UserName = "张七",Age = 20, Sex = "男",Email = "aklsdf@163.com"},
41 new UserInfo{UserId = 7,UserName = "李八",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
42 new UserInfo{UserId = 8,UserName = "李九",Age = 21, Sex = "男",Email = "aklsdf@163.com"},
43 new UserInfo{UserId = 9,UserName = "张十",Age = 20, Sex = "男",Email = "aklsdf@163.com"}
44 };
45 //ViewData["Message"] = "Welcome to ASP.NET MVC!";
46
47 return View(new IndexModel(userInfo, 6, page, 100));
48 }
49
50 public ActionResult About()
51 {
52 return View();
53 }
54 }
55}
56
接下来,是我的Models里的一个用户类UserInfo.cs:
Code
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Linq;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.HtmlControls;
9 using System.Web.UI.WebControls;
10 using System.Web.UI.WebControls.WebParts;
11 using System.Xml.Linq;
12
13 namespace PartialViewTest.Models
14 {
15 public class UserInfo
16 {
17 public int UserId
18 {
19 set;
20 get;
21 }
22 public string UserName
23 {
24 set;
25 get;
26 }
27
28 public string Sex
29 {
30 set;
31 get;
32 }
33
34 public int Age
35 {
36 set;
37 get;
38 }
39
40 public string Email
41 {
42 set;
43 get;
44 }
45 }
46 }
47
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Linq;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.HtmlControls;
9 using System.Web.UI.WebControls;
10 using System.Web.UI.WebControls.WebParts;
11 using System.Xml.Linq;
12
13 namespace PartialViewTest.Models
14 {
15 public class UserInfo
16 {
17 public int UserId
18 {
19 set;
20 get;
21 }
22 public string UserName
23 {
24 set;
25 get;
26 }
27
28 public string Sex
29 {
30 set;
31 get;
32 }
33
34 public int Age
35 {
36 set;
37 get;
38 }
39
40 public string Email
41 {
42 set;
43 get;
44 }
45 }
46 }
47
接下来,是几个View的文件,包括那些在View里的Model文件:
Index.aspx:
Code
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PartialViewTest.Views.Home.IndexModel>" %>
<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
Home Page
</asp:Content>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
<table width="500" border="0" cellpadding="0" cellspacing="0">
<%Html.RenderPartial("IndexUserRow",new PartialViewTest.Views.Home.IndexUserRowModel(true,null,0));%>
<%((List<PartialViewTest.Models.UserInfo>)Model.UserInfo).ForEach((u) => Html.RenderPartial("IndexUserRow", new PartialViewTest.Views.Home.IndexUserRowModel(false, u, 0))); %>
</table>
<p>
<%Html.RenderPartial("Pager", new PartialViewTest.Views.Shared.PagerModel(Model.PageSize, Model.PageNumber, Model.TotalCount));%>
</p>
</asp:Content>
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PartialViewTest.Views.Home.IndexModel>" %>
<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
Home Page
</asp:Content>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
<table width="500" border="0" cellpadding="0" cellspacing="0">
<%Html.RenderPartial("IndexUserRow",new PartialViewTest.Views.Home.IndexUserRowModel(true,null,0));%>
<%((List<PartialViewTest.Models.UserInfo>)Model.UserInfo).ForEach((u) => Html.RenderPartial("IndexUserRow", new PartialViewTest.Views.Home.IndexUserRowModel(false, u, 0))); %>
</table>
<p>
<%Html.RenderPartial("Pager", new PartialViewTest.Views.Shared.PagerModel(Model.PageSize, Model.PageNumber, Model.TotalCount));%>
</p>
</asp:Content>
IndexModel.cs:
Code
using System;
using System.Data;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using PartialViewTest.Models;
namespace PartialViewTest.Views.Home
{
public class IndexModel
{
public IndexModel(IEnumerable<UserInfo> userInfo, int pageSize, int pageNumber, int totalCount)
{
this.UserInfo = userInfo;
this.PageSize = pageSize;
this.PageNumber = pageNumber;
this.TotalCount = totalCount;
}
public IEnumerable<UserInfo> UserInfo
{
get;
private set;
}
public int PageSize
{
get;
private set;
}
public int PageNumber
{
get;
private set;
}
public int TotalCount
{
get;
private set;
}
}
}
using System;
using System.Data;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using PartialViewTest.Models;
namespace PartialViewTest.Views.Home
{
public class IndexModel
{
public IndexModel(IEnumerable<UserInfo> userInfo, int pageSize, int pageNumber, int totalCount)
{
this.UserInfo = userInfo;
this.PageSize = pageSize;
this.PageNumber = pageNumber;
this.TotalCount = totalCount;
}
public IEnumerable<UserInfo> UserInfo
{
get;
private set;
}
public int PageSize
{
get;
private set;
}
public int PageNumber
{
get;
private set;
}
public int TotalCount
{
get;
private set;
}
}
}
唉呀,真多,幸好这只是一个测试的东西.
IndexUserRow.ascx:
Code
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<PartialViewTest.Views.Home.IndexUserRowModel>" %>
<%PartialViewTest.Views.Heplers.If(Model.RenderHeader,
() =>
{%>
<tr>
<th>
UserId
</th>
<th>
UserName
</th>
<th>
UserSex
</th>
<th>
Age
</th>
<th>
Email
</th>
</tr>
<%},
() =>
{
string c = (Model.Index % 2 == 0) ? "even" : "odd";%>
<tr class="<%=c%>">
<td><%=Model.UserInfo.UserId%></td>
<td><%=Model.UserInfo.UserName%></td>
<td><%=Model.UserInfo.Sex%></td>
<td><%=Model.UserInfo.Age%></td>
<td><%=Model.UserInfo.Email%></td>
</tr>
<%}
);
%>
然后是它的Model<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<PartialViewTest.Views.Home.IndexUserRowModel>" %>
<%PartialViewTest.Views.Heplers.If(Model.RenderHeader,
() =>
{%>
<tr>
<th>
UserId
</th>
<th>
UserName
</th>
<th>
UserSex
</th>
<th>
Age
</th>
<th>
</th>
</tr>
<%},
() =>
{
string c = (Model.Index % 2 == 0) ? "even" : "odd";%>
<tr class="<%=c%>">
<td><%=Model.UserInfo.UserId%></td>
<td><%=Model.UserInfo.UserName%></td>
<td><%=Model.UserInfo.Sex%></td>
<td><%=Model.UserInfo.Age%></td>
<td><%=Model.UserInfo.Email%></td>
</tr>
<%}
);
%>
IndexUserRowModel.cs:
Code
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using PartialViewTest.Models;
namespace PartialViewTest.Views.Home
{
public class IndexUserRowModel
{
public IndexUserRowModel(bool renderHeader, UserInfo userInfo, int index)
{
this.RenderHeader = renderHeader;
this.UserInfo = userInfo;
this.Index = index;
}
public bool RenderHeader
{
get;
private set;
}
public UserInfo UserInfo
{
get;
private set;
}
public int Index
{
get;
private set;
}
}
}
List.aspx:using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using PartialViewTest.Models;
namespace PartialViewTest.Views.Home
{
public class IndexUserRowModel
{
public IndexUserRowModel(bool renderHeader, UserInfo userInfo, int index)
{
this.RenderHeader = renderHeader;
this.UserInfo = userInfo;
this.Index = index;
}
public bool RenderHeader
{
get;
private set;
}
public UserInfo UserInfo
{
get;
private set;
}
public int Index
{
get;
private set;
}
}
}
Code
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PartialViewTest.Views.Home.IndexModel>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
List
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<table width="500" border="0" cellpadding="0" cellspacing="0">
<%Html.RenderPartial("IndexUserRow",new PartialViewTest.Views.Home.IndexUserRowModel(true,null,0));%>
<%((List<PartialViewTest.Models.UserInfo>)Model.UserInfo).ForEach((u) => Html.RenderPartial("IndexUserRow", new PartialViewTest.Views.Home.IndexUserRowModel(false, u, Model.PageNumber))); %>
</table>
<p>
<%Html.RenderPartial("Pager", new PartialViewTest.Views.Shared.PagerModel(Model.PageSize, Model.PageNumber, Model.TotalCount));%>
</p>
</asp:Content>
Pager.ascx:<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PartialViewTest.Views.Home.IndexModel>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
List
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<table width="500" border="0" cellpadding="0" cellspacing="0">
<%Html.RenderPartial("IndexUserRow",new PartialViewTest.Views.Home.IndexUserRowModel(true,null,0));%>
<%((List<PartialViewTest.Models.UserInfo>)Model.UserInfo).ForEach((u) => Html.RenderPartial("IndexUserRow", new PartialViewTest.Views.Home.IndexUserRowModel(false, u, Model.PageNumber))); %>
</table>
<p>
<%Html.RenderPartial("Pager", new PartialViewTest.Views.Shared.PagerModel(Model.PageSize, Model.PageNumber, Model.TotalCount));%>
</p>
</asp:Content>
Code
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<PartialViewTest.Views.Shared.PagerModel>" %>
<%= PartialViewTest.Views.Heplers.If(
Model.HasPreviousPage,
() => Html.ActionLink("上一页", "List", new { page = Model.PageNumber - 1 }),
() => "上一页"
)%>
|
<% for (int i = 1; i <= (Model.TotalCount - 1) / Model.PageSize + 1; i++)
{%>
<% if (i > 1) { %> | <%} %>
<% if (i == Model.PageNumber)
{ %>
<strong><%=i%></strong>
<%}
else
{ %>
<%=Html.ActionLink(i.ToString(), "List", new { page=i})%>
<%} %>
<%} %>
|
<%= PartialViewTest.Views.Heplers.If(
Model.HasNextPage,
() => Html.ActionLink("下一页", "List", new { page = Model.PageNumber + 1 }),
() => "下一页"
)%>
PagerModel.cs:<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<PartialViewTest.Views.Shared.PagerModel>" %>
<%= PartialViewTest.Views.Heplers.If(
Model.HasPreviousPage,
() => Html.ActionLink("上一页", "List", new { page = Model.PageNumber - 1 }),
() => "上一页"
)%>
|
<% for (int i = 1; i <= (Model.TotalCount - 1) / Model.PageSize + 1; i++)
{%>
<% if (i > 1) { %> | <%} %>
<% if (i == Model.PageNumber)
{ %>
<strong><%=i%></strong>
<%}
else
{ %>
<%=Html.ActionLink(i.ToString(), "List", new { page=i})%>
<%} %>
<%} %>
|
<%= PartialViewTest.Views.Heplers.If(
Model.HasNextPage,
() => Html.ActionLink("下一页", "List", new { page = Model.PageNumber + 1 }),
() => "下一页"
)%>
Code
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using PartialViewTest.Models;
using System.Collections.Generic;
namespace PartialViewTest.Views.Shared
{
public class PagerModel
{
public PagerModel(int pageSize, int pageNumber, int totalCount)
{
this.HasPreviousPage = pageNumber > 1 ? true : false;
this.HasNextPage = pageNumber * pageSize < totalCount ? true : false;
this.MaxPageNumber = (totalCount - 1) / pageSize + 1;
this.PageSize = pageSize;
this.PageNumber = pageNumber;
this.TotalCount = totalCount;
}
public bool HasPreviousPage
{
get;
private set;
}
public bool HasNextPage
{
get;
private set;
}
public int MaxPageNumber
{
get;
private set;
}
public int PageSize
{
get;
private set;
}
public int PageNumber
{
get;
private set;
}
public int TotalCount
{
get;
private set;
}
}
}
还有一个辅助方法Helper.cs:using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using PartialViewTest.Models;
using System.Collections.Generic;
namespace PartialViewTest.Views.Shared
{
public class PagerModel
{
public PagerModel(int pageSize, int pageNumber, int totalCount)
{
this.HasPreviousPage = pageNumber > 1 ? true : false;
this.HasNextPage = pageNumber * pageSize < totalCount ? true : false;
this.MaxPageNumber = (totalCount - 1) / pageSize + 1;
this.PageSize = pageSize;
this.PageNumber = pageNumber;
this.TotalCount = totalCount;
}
public bool HasPreviousPage
{
get;
private set;
}
public bool HasNextPage
{
get;
private set;
}
public int MaxPageNumber
{
get;
private set;
}
public int PageSize
{
get;
private set;
}
public int PageNumber
{
get;
private set;
}
public int TotalCount
{
get;
private set;
}
}
}
Code
using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace PartialViewTest.Views
{
public static class Heplers
{
public static string If(bool condition,Func<string> value,Func<string> elseValue )
{
return condition ? value() : elseValue();
}
public static void ForEach(int includeMin, int excludeMax, Action<int> action)
{
for (int i = includeMin; i < excludeMax; i++) action(i);
}
public static void If(bool condition, Action action, Action elseAction)
{
if (condition)
action();
else if (elseAction != null)
elseAction();
}
public static void ForEach<T>(this IEnumerable<T> items,Action<T> action)
{
foreach (var item in items) action(item);
}
public static void ForEach<T>(this IEnumerable<T> items, Action<T,int> action)
{
int index = 0;
foreach (var item in items) action(item,index++);
}
}
}
最后,我还修改了CSS:using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace PartialViewTest.Views
{
public static class Heplers
{
public static string If(bool condition,Func<string> value,Func<string> elseValue )
{
return condition ? value() : elseValue();
}
public static void ForEach(int includeMin, int excludeMax, Action<int> action)
{
for (int i = includeMin; i < excludeMax; i++) action(i);
}
public static void If(bool condition, Action action, Action elseAction)
{
if (condition)
action();
else if (elseAction != null)
elseAction();
}
public static void ForEach<T>(this IEnumerable<T> items,Action<T> action)
{
foreach (var item in items) action(item);
}
public static void ForEach<T>(this IEnumerable<T> items, Action<T,int> action)
{
int index = 0;
foreach (var item in items) action(item,index++);
}
}
}
在Site.css最后加了
.even
{
color:#000;
}
.odd
{
color:#f00;
}
好了,以上是我全部代码,不正确的地方,请指正.