我們創建一個EmployeeRepository對象來進行數據的獲取
public interface IEmployeeRepository
{
IEnumerable<Employee> GetEmployees(string id =
}
public class EmployeeRepository : IEmployeeRepository
{
private static IList<Employee> employees;
static EmployeeRepository()
{
employees = new List<Employee>()
employees
employees
employees
}
public IEnumerable<Employee> GetEmployees(string id =
{
return employees
}
}
我們創建了一個具有如下定義的EmployeeController
public class EmployeeController : Controller
{
[Dependency]
public IEmployeeRepository Repository { get; set; }
public ActionResult GetAllEmployees()
{
var employees = this
return View(
}
public ActionResult GetEmployeeById(string id)
{
Employee employee = this
if (null == employee)
{
throw new HttpException(
}
return View(
}
}
EmployeeController定義了兩個基本的Action方法
[
From:http://tw.wingwit.com/Article/program/net/201311/16071.html