如何使用常见的布局和样式在多个Asp.net MVC应用程序 [英] How to use common Layout and styles across multiple Asp.net MVC applications

查看:109
本文介绍了如何使用常见的布局和样式在多个Asp.net MVC应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有有相同的外观和感觉Telerik的多个剃须刀MVC4项目Visual Studio解决方案。我不希望有相同的布局,CSS /样式,图像和所有MVC4项目复制js文件。什么是实现这一目标的可重用性的最佳方式?我试图创建一个commonUI项目的虚拟目录,并试图引用_layout.cshtml使用的http://本地主机/ ......在_ViewStart.cshtml但它抱怨说:HTTP:/localhost/MyMvcApp/Views/Shared/_Layout.cshtml'不是一个有效的虚拟路径

I have a visual studio solution with multiple telerik MVC4 razor projects having same look and feel. I don't want to have same layout, CSS/styles, images and js files copied in all MVC4 projects. What is the best way to accomplish this re-usability? I tried creating a virtual directory of a commonUI project and tried to refer _layout.cshtml using http://localhost/... in _ViewStart.cshtml but it complained saying "http:/localhost/MyMvcApp/Views/Shared/_Layout.cshtml' is not a valid virtual path."

请帮帮忙!

推荐答案

四点建议:

1)搜索领域,可能的而不是单独的项目,这些都是在同一个系统(管理员,等真的不同组件。)?

1) Look into areas, maybe instead of having separate projects these are really different components of the same system (admin, etc.)?

2)使用Visual Studio中添加现有的项目,并通过添加链接的项目。这仍然复制它们的部署,但可以保留一个来源。

2) Use add existing item in visual studio and add the items via links. This still duplicates them for deployment, but you can keep one source.

3)考虑建立自己的NuGet包这样做。这样,虽然你会复制CSS,你将它打包的图像,并根据需要可以更新包。这样做的好处是,你可以更新,而不必重新测试其他(如果他们是分开的,1)不适用)一个项目。

3) Consider doing this by building your own nuget package. That way although you would copy the CSS and images you would have it packaged up and could update the package as needed. The benefit is that you can update one project while not having to re-test the other (if they are separate and 1) doesn't apply).

4)我觉得比其他人这一个丑陋,但在IIS我相信你可以在文件夹映射,所以你可以在你的项目是指这些文件由链接,而不是他们那里部署,然后在相应的文件夹在映射使用单一的源路径部署时间。

4) I find this one uglier than the rest, but in IIS I believe you can map in folders, so you could refer to these files by links in your project, not deploy them there and then map in the appropriate folder at deployment time using a single source path.

据我所知,没有办法分享了应用程序的路径。

I know of no way to share up the application path.

我从来没有试过,所以不能保证它的工作,但也许编译一个单独的项目共享项目,然后引用的所有其他项目的DLL。

I have never tried this before, so can't vouch for it working, but maybe compile your shared items in a separate project and then reference the DLL in all other projects.

我发现的引用是这样,但同样,我还没有确认这工作,只是觉得这可能是探索出一条可行的路径:

The reference I found is this, but again, I haven't confirmed that this works, just think this could be a viable path to explore:

<一个href=\"http://www.chrisvandesteeg.nl/2010/11/22/embedding-$p$p-compiled-razor-views-in-your-dll/\">http://www.chrisvandesteeg.nl/2010/11/22/embedding-$p$p-compiled-razor-views-in-your-dll/

这篇关于如何使用常见的布局和样式在多个Asp.net MVC应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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