無法加載索引頁面 我是否需要在RouteConfig.cs中進行更改?無法加載頁面
Index.chtml
@model IEnumerable<MVCDemo.Models.Employee>
@using MVCDemo.Models;
@{
ViewBag.Title = "Index";
}
<div>
<h2>Index</h2>
<ul>
@foreach (Employee employee in @Model)
{
@Html.ActionLink(employee.Name, "Details", new { id = employee.EmployeeId})
}
</ul>
</div>
EmployeeController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCDemo.Models;
namespace MVCDemo.Controllers
{
public class EmployeeController : Controller
{
public ActionResult Index()
{
List<Employee> employee = new List<Employee>();
employee.Add(new Employee()
{
EmployeeId = 101,
Name = "John",
Gender = "Male",
City = "London"
});
employee.Add(new Employee()
{
EmployeeId = 102,
Name = "Kacay",
Gender = "FeMale",
City = "Floria"
});
employee.Add(new Employee()
{
EmployeeId = 103,
Name = "Sasha",
Gender = "FeMale",
City = "USA"
});
return View(employee);
}
public ActionResult Details()
{
Employee employee = new Employee()
{
EmployeeId = 101,
Name = "John",
Gender = "Male",
City = "London"
};
return View(employee);
}
}
}
Details.chtml
@model MVCDemo.Models.Employee
@{
ViewBag.Title = "Details";
}
<h2>Details</h2>
<tr>
<td>
EmployeeId :
</td>
<td>
@Model.EmployeeId
</td>
<td>
Name :
</td>
<td>
@Model.Name
</td>
<td>
Gender :
</td>
<td>
@Model.Gender
</td>
<td>
City :
</td>
<td>
@Model.City
</td>
</tr>
Employee.cs(型號)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MVCDemo.Models
{
public class Employee
{
public int EmployeeId { get; set;}
public string Name { get; set; }
public string Gender { get; set; }
public string City { get; set; }
}
}
無法加載索引頁面 我是否需要在RouteConfig.cs中進行更改?
當你嘗試加載它時會出現什麼錯誤? – krillgar 2015-02-12 03:07:04