ASP.NET实现MVC的Lambda表达式
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
实现MVC的Lambda表达式
就是这样虽然有了智能提⽰,但是反应很慢,有时候需要编译⼏次才会正确,这种改造⽅法有点像mvc,都是lambda表达式,这⾥记录下⽅法。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace .bind.data
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//⼀群学⽣
var students = new[]
{
new Student { Name = "mike", Age = 23 },
new Student { Name = "jane", Age = 12 },
new Student { Name = "frank", Age = 25 },
new Student { Name = "susan", Age = 32 },
};
rptStudents.DataSource = students;
rptStudents.DataBind();
}
protected virtual TREsult ExpHelper<TEntity, TREsult>(Func<TEntity, TREsult> func)
{
var item = base.GetDataItem(); return func((TEntity)item);
}
protected TResult Eval<TResult>(Func<Student, TResult> func)
{
return ExpHelper<Student, TResult>(func);
}
}
}
view :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits=".bind.data.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Repeater ID="rptStudents" runat="server">
<ItemTemplate>
<li>
<%#Eval(m => )%></li>
</ItemTemplate>
</asp:Repeater>
</form>
</body>
</html>。