net MVC,从不同的控制器调用视图

时间:2022-02-27 00:34:59

I have an EmployeeController and ShiftController. 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). In EmpShifts.aspx, I want to give a link to Create New Shift. I want to know how to call Create View of Shifts from EmpShifts.aspx.

我有一个雇员控制和移位控制器。在EmployeeController的索引视图中,我展示了带有编辑、删除和getshift选项的EmployeeDetails(这将得到该员工的所有转换——EmpShifts.aspx)。在EmpShifts。aspx,我想给一个链接来创建新的移位。我想知道如何从EmpShifts.aspx调用Create View。

Am I having the wrong design structure. Suggestions on that are welcome.

我的设计结构不对吗?对此,欢迎提出建议。

1 个解决方案

#1


2  

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:

同样的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.

你的设计是正确的。在某些视图中有指向其他控制器动作的链接/表单是完全正常的。

#1


2  

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:

同样的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.

你的设计是正确的。在某些视图中有指向其他控制器动作的链接/表单是完全正常的。