asp.net-mvc-4 - asp.net mvc从不同 Controller 调用单个 View

标签 asp.net-mvc-4

我有4个不同的ActionResult在2个不同的 Controller 中运行,我创建了一个部分 View StudentList,我想使用相同的partialView,因为模型是相同的。

从第一个 ActionResult 我想按类(class)显示 StudentList 从第二个 ActionResult 我想按类主任显示学生列表 从第三个 ActionResult 我想按未付费用显示学生列表 从第 4 个 ActionResult 开始,我想按缺勤学生显示 StudentList

所有 4 个都返回 Student 的 Model 类型。 包含字段 StudentName、ParentMobileNo

是否可以不创建4个不同的View并使用单个局部 View 或单个 View 来显示结果。

问候

最佳答案

是的。创建共享 View ,并在 Controller 返回 ActionResult 时传递 View 名称。

return View("StudentList", model);

或者,如果您想从 View 中渲染部分内容:

@{ Html.RenderPartial("StudentList", model); }

关于asp.net-mvc-4 - asp.net mvc从不同 Controller 调用单个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18292838/

相关文章:

c# - 部分 View 验证错误在部分 View 上获取触发 View 获取调用本身

asp.net - 找不到类型或 namespace 名称 'Moq'(是否缺少using指令或程序集引用?)

asp.net-mvc-4 - 如何处理数据表中的搜索参数

c# - 使用 MVC 显示表单错误

c# - MVC Entity Framework - 处理 DbContext 的实例?

asp.net-mvc-4 - 更改 web.config 的 appSettings 中的值时在 IIS 中重新启动网站

asp.net-mvc - 将 id 从 View 传递给 Controller

c# - Owin 授权拒绝角色

jquery - 从部分 View MVC 传递变量

c# - SQL Server session 状态的 Session_End() 替代方法