开发者

ASP.net MVC, calling a view from different Controller

开发者 https://www.devze.com 2023-03-07 01:46 出处:网络
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 开

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.

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:

<% 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号