asp.net mvc我可以使用一种视图来定位多种操作方法吗?还是我每个人都需要一个单独的视图? [英] asp.net mvc Can i have one view for multiple action methods to target? or do i need a separate view for each?

查看:50
本文介绍了asp.net mvc我可以使用一种视图来定位多种操作方法吗?还是我每个人都需要一个单独的视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一个菜单控制器来根据所使用的其他控制器来驱动顶部菜单链接.每个其他控制器的每个视图都有一个单独的嵌套母版页.

I have set up a menu-controller to drive the top menu links based on which other controller is being used. Each other controller has a separate nested master page for each of its views.

所以,我有一个菜单控制器,其中有几种返回视图结果的方法,每个方法一个,或者站点的部分".因此,当前每种方法都有其自己的视图来呈现菜单.但是用于渲染菜单的每​​个视图都是相同的代码,唯一改变的是控制器方法中基于要渲染的链接的逻辑.

so, i have a menu-controller with several methods that return viewresults, one per each controller, or "section" of the site. So currently each of these methods has its own view to render the menu. but each view to render the menu is the same code, the only thing that changes is the logic in the controller methods based on which links to render.

有什么办法可以使所有这些控制器动作都针对同一视图?因为所有人的看法都一样?

is there any way to have all of these controller actions target the same view? since the view is the same for all?

谢谢

推荐答案

是的,这是一种常见的做法.

Yes, that is a common practice.

return View("Menu");

这篇关于asp.net mvc我可以使用一种视图来定位多种操作方法吗?还是我每个人都需要一个单独的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆