有什麼理由區的不工作?從你所描述的,我不明白他們爲什麼不會。
- 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 ...
}
}