在ASP.NET中使用区域5 [英] Using Areas in ASP.NET 5
问题描述
我有一个ASP.NET vNext(5)项目。我想两个方面添加到项目中。我的问题是,我该如何在vNext注册领域?在 System.Web.Mvc
命名空间消失了,这是在AreaRegistrationContext所在地。我开始寻找在GitHub上的MVC源$ C $ C。我找到的<一个href=\"https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.Core/Areas/AreaAttribute.cs\">Area属性。但是,我不知道现在该怎么利用它。
I have an ASP.NET vNext (5) project. I am trying to add two areas to the project. My question is, how do I register areas in vNext? The System.Web.Mvc
namespace is gone, which is where AreaRegistrationContext was located. I started looking in the MVC source code on GitHub. I found the Area attribute. However, I'm not sure how to utilize it now.
可有人请向我解释(或提供链接)如何在ASP.NET vNext使用区域?
Can someone please explain to me (or provide a link) of how to use Areas in ASP.NET vNext?
感谢您!
推荐答案
。区域的路由添加像正常路线。这里有一个例子:<一href=\"https://github.com/aspnet/Mvc/blob/dev/samples/MvcSample.Web/Startup.cs\">https://github.com/aspnet/Mvc/blob/dev/samples/MvcSample.Web/Startup.cs
In vNext you register and configure the services you are going to use in Startup.cs. Area routes are added like normal routes. There is a sample here: https://github.com/aspnet/Mvc/blob/dev/samples/MvcSample.Web/Startup.cs
您可以添加一个MVC路线像这样的区域:
You could add an MVC route for an area like this:
app.UseMvc(routes =>
{
routes.MapRoute("areaRoute", "{area:exists}/{controller}/{action}");
});
或者你可以使用这样的路径属性: [路线([区域] /家庭)]
[区域]属性装饰包含在该区域控制器。只需要一个参数,该地区的名称。这里有一个例子:<一href=\"https://github.com/aspnet/Mvc/blob/dev/samples/MvcSample.Web/Areas/Travel/Controllers/HomeController.cs\">https://github.com/aspnet/Mvc/blob/dev/samples/MvcSample.Web/Areas/Travel/Controllers/HomeController.cs
The [Area] attribute decorates controllers included in the area. It takes only one parameter, the name of the area. Here's an example: https://github.com/aspnet/Mvc/blob/dev/samples/MvcSample.Web/Areas/Travel/Controllers/HomeController.cs
[Area("Travel")]
public class HomeController : Controller
{ //... }
这篇关于在ASP.NET中使用区域5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!