如何在ASP.NET MVC中使用另一个项目的部分视图

编程入门 行业动态 更新时间:2024-10-26 14:34:27
本文介绍了如何在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中使用另一个项目的部分视图

本文发布于:2023-11-15 10:37:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1593678.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   项目   如何在   NET   ASP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!