[英]ASP.NET Core 2.1. Razor UI Class Library in MVC View
I'm currently working on an ASP.NET Core 2.1. 我目前正在使用ASP.NET Core 2.1。 RC1 Final (May 2018) demo application.
RC1 Final (2018年5月)演示应用程序。 I try to use the new Razor UI Library in my ASP.NET Core MVC application.
我尝试在ASP.NET Core MVC应用程序中使用新的Razor UI库。
Thus, in my Solution I have 2 Projects: 因此,在我的解决方案中,我有2个项目:
The structure of my Razor Class Library is very simple: 我的Razor类库的结构非常简单:
The cshtml of Page1.chtml looks like that: Page1.chtml的cshtml看起来像这样:
@page
@model RazorClassLib1.MyFeature.Pages.Page1Model
@{
Layout = "_Layout";
}
<h1>Hello From the Razor ClassLib1</h1>
Now I want to use this Page1.cshtml Razor component in my MVC View. 现在,我想在我的MVC视图中使用此Page1.cshtml Razor组件。 This feature would be useful to organize and reuse razor pages within my application.
此功能对于在我的应用程序中组织和重用剃须刀页面很有用。
Unfortunately I have no idea how to achieve this. 不幸的是,我不知道如何实现这一目标。 I was following this example:
我正在关注以下示例:
http://www.talkingdotnet.com/asp-net-core-2-1-razor-ui-as-class-library/ http://www.talkingdotnet.com/asp-net-core-2-1-razor-ui-as-class-library/
though it seems to work only for a razor page project, but I would need it in my MVC projct. 尽管它似乎仅适用于剃须刀页面项目,但是我的MVC项目中需要它。
Do you know how to use a Razor Class Library in ASP.NET MVC Core 2.1. 您知道如何在ASP.NET MVC Core 2.1中使用Razor类库。 Views?
看法?
Thank you very much. 非常感谢你。
https://gunnarpeipman.com/aspnet/razor-class-library-mvc/ https://gunnarpeipman.com/aspnet/razor-class-library-mvc/
explains how to set it up. 解释了如何设置。
There are some things to know: Controllers must have AreaAttribute Web application must have area route defined. 有一些事情要知道:控制器必须具有AreaAttribute Web应用程序,必须已定义区域路由。
I think there work arounds using the areas, but I am researching this myself. 我认为可以使用这些区域,但是我自己正在对此进行研究。 will update the answer when I have figured it out.
当我确定答案时,它将更新答案。
Below link also explains how to make the area name dynamic: https://blog.tech-fellow.net/2018/11/11/razor-ui-class-library-with-dynamic-area-name/ 以下链接还介绍了如何使区域名称动态化: https : //blog.tech-fellow.net/2018/11/11/razor-ui-class-library-with-dynamic-area-name/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.