如何在ASP.NET MVC中使用另一个项目的部分视图 [英] How to use partial view from another project in asp.net mvc

查看:305
本文介绍了如何在ASP.NET MVC中使用另一个项目的部分视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个MVC项目,一个作为父项目,另一个作为子项目.子项目将引用添加到父项目.我喜欢使用子项目中父项目的部分视图,例如-

I have two MVC projects one as a parent project and the other as a child project. The child project adds reference to the parent project. I like to use partial views from the parent project from the child project something like -

@Html.Partial("_GenericGreeting")<-在子项目中

@Html.Partial("_GenericGreeting") <-- in child project

_GenericGreeting.cshtml<-在父项目中

_GenericGreeting.cshtml <-- is in parent project

子项目是启动的项目.我的意思是父项目就像一个基础/共享项目. RazorGenerator已安装在两个项目上,并且每个项目都可以编译为单个程序集.

The child project is the project that starts up. Parent project i mean is like a base/shared project. RazorGenerator has been installed on both projects and each projects can be compiled into single assembles.

当我运行项目时,我只会遇到以下错误.

When I ran the project, i'm only getting this following error.

找不到部分视图'_GenericGreeting'或没有视图引擎 支持搜索到的位置.

The partial view '_GenericGreeting' was not found or no view engine supports the searched locations.

如果我复制部分视图并将其粘贴到子项目中,那很好,但是我不想复制文件.

If i copy the partial view and paste it into the child project it's fine but i don't want to duplicate the files.

我尝试了

I have tried this post but no luck but maybe i'm not adding it right.

推荐答案

不是很好,但是简单的解决方案可以解决您的问题.重载之一@Html.Partial()允许您将完整路径写入视图.

Not really good, but simple solution that can solve your problem. One of overloads @Html.Partial() allows you to write full path to your View.

类似这样的东西:

@Html.Partial("~/View/Shared/_GenericGreeting.cshtml")

这篇关于如何在ASP.NET MVC中使用另一个项目的部分视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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