如何在两个 ASP.NET MVC 区域中使用一个视图?
我有一个 ASP.NET MVC 应用程序,在其中我设置了两个区域。但是,有一个视图我在A区实现了,但是我还需要在B区使用它,如何在B区渲染它呢?我的意思是, Html.RenderPartial
方法将视图的名称作为输入参数。但它怎么知道我指的是哪个视图呢?换句话说,如果我的视图名称是 Countries
,并且我想在区域 B 中编写 Html.RenderPartial("Countries")
,ASP.NET MVC 如何知道我你说的是属于A区的景色吗?
I have an ASP.NET MVC application, and in it, I have set up two areas. However, there is one view that I have implemented in Area A, but I also need to use it in Area B. How can I render it in Area B? I mean, Html.RenderPartial
method takes the name of the view as the input parameter. But how it's gonna know which view do I mean? In other words, if my view's name is Countries
, and I want to write Html.RenderPartial("Countries")
in Area B, how ASP.NET MVC knows that I'm talking about a view which belongs to Area A?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将该部分视图放置在 Views 文件夹(项目目录中的视图文件夹,而不是区域)内的 Shared 文件夹中。 ASP.NET MVC 将检查该位置,您无需定义任何路径。您可以在视图中使用
Html.RenderPartial("SomePartial");
。You can place that partial view in Shared folder inside Views folder(the views folder in the project directory, not area). ASP.NET MVC will check that place and you wouldn't need to define any path. You can use
Html.RenderPartial("SomePartial");
in your view.