有什么理由区的不工作?从你所描述的,我不明白他们为什么不会。
- Areas
- Students
- Controllers
HomeController Handles base /Students/ route
InformationController ~/Students/Information/{action}/{id}
StatusController ~/Students/Status/{action}/{id}
...
- Models
- Views
Home/
Information/
Status/
...
Shared/ Stick common views in here
如果你一个怪物控制器(或谐音)的参数设置,你的控制器应在它很少有实际的“查看代码”。保留所有这些以查看模型 - 控制器只需传递所需的资源即可构建视图数据,从而保持控制器精简。
也就是说,
public class StudentController
{
...
// Actually I prefer to bind the id to a model and handle 404
// checking there, vs pushing that boiler plate code further down
// into the controller, but this is just a quick example.
public ActionResult Information(int id)
{
return View(new InformationPage(this.StudentService, id));
}
}
然后,InformationPage
是您的模型将处理扩建适用于该视图中的所有信息之一。
public class InformationPage
{
public Student Student { get; set; }
public InformationPage(StudentService service, int studentId)
{
Student = service.FindStudent(studentId);
... Other view data ...
}
}