我有两个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中使用另一个项目的部分视图
发布评论