简体   繁体   English

ASP.net MVC,从不同的Controller调用视图

[英]ASP.net MVC, calling a view from different Controller

I have an EmployeeController and ShiftController . 我有一个EmployeeControllerShiftController In the Index View of EmployeeController I show EmployeeDetails with options of Edit , Delete and GetShifts (this gets all the shifts of that employee - EmpShifts.aspx). EmployeeControllerIndex视图中,我显示了EmployeeDetails其中包含EditDeleteGetShifts选项(这将获得该员工的所有轮班 - EmpShifts.aspx)。 In EmpShifts.aspx, I want to give a link to Create New Shift . 在EmpShifts.aspx中,我想提供Create New Shift的链接。 I want to know how to call Create View of Shifts from EmpShifts.aspx . 我想知道如何从EmpShifts.aspx调用Create View of Shifts。

Am I having the wrong design structure. 我的设计结构是否错误。 Suggestions on that are welcome. 欢迎提出建议。

When generating links you can specify the action and controller they are pointing to: 生成链接时,您可以指定它们指向的操作和控制器:

<%= Html.ActionLink("Create new shift", "create", "shift") %>

Same for HTML forms allowing you to POST: 对于允许您POST的HTML表单也是如此:

<% using (Html.BeginForm("create", "shift")) <% { %>
    ...
<% } %>

Your design is correct. 你的设计是对的。 It is perfectly normal for having links/forms in some view pointing to other controller actions. 在某些视图中指向其他控制器操作的链接/表单是完全正常的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM