From cfb06c0de39599f0e922311f6795b34cc754d7e2 Mon Sep 17 00:00:00 2001 From: Yishai Galatzer Date: Mon, 17 Mar 2014 23:19:34 -0700 Subject: [PATCH] Areas feature - Phase I 1. Areas defined by the Area attribute 2. Areas are a routeconstraint on the actiondescriptor 3. Areas find pages through route values Other changes: 1. Remove Path from ActionDescriptor - It doesn't make sense with this change 2. Add sample Area --- .../Areas/Travel/Controllers/Flight.cs | 13 ++++ .../Areas/Travel/Views/Flight/Fly.cshtml | 33 ++++++++++ samples/MvcSample.Web/Startup.cs | 3 + .../MvcSample.Web/Views/Shared/_Layout.cshtml | 5 +- .../ActionDescriptor.cs | 3 - .../Areas/AreaAttribute.cs | 17 +++++ ...outeConstraintsActionDescriptorProvider.cs | 66 +++++++++++++++++++ .../DefaultControllerFactory.cs | 1 + .../ReflectedActionDescriptor.cs | 12 ---- .../ReflectedActionDescriptorProvider.cs | 4 +- .../RouteConstraintAttribute.cs | 19 ++++++ .../Extensions/DictionaryExtensions.cs | 21 ++++++ .../ViewEngine/RazorViewEngine.cs | 10 +-- src/Microsoft.AspNet.Mvc/MvcServices.cs | 2 + 14 files changed, 188 insertions(+), 21 deletions(-) create mode 100644 samples/MvcSample.Web/Areas/Travel/Controllers/Flight.cs create mode 100644 samples/MvcSample.Web/Areas/Travel/Views/Flight/Fly.cshtml create mode 100644 src/Microsoft.AspNet.Mvc.Core/Areas/AreaAttribute.cs create mode 100644 src/Microsoft.AspNet.Mvc.Core/Areas/ReflectedRouteConstraintsActionDescriptorProvider.cs create mode 100644 src/Microsoft.AspNet.Mvc.Core/RouteConstraintAttribute.cs create mode 100644 src/Microsoft.AspNet.Mvc.Razor/Extensions/DictionaryExtensions.cs diff --git a/samples/MvcSample.Web/Areas/Travel/Controllers/Flight.cs b/samples/MvcSample.Web/Areas/Travel/Controllers/Flight.cs new file mode 100644 index 0000000000..38e5c7af80 --- /dev/null +++ b/samples/MvcSample.Web/Areas/Travel/Controllers/Flight.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNet.Mvc; + +namespace MvcSample.Web +{ + [Area("Travel")] + public class Flight : Controller + { + public IActionResult Fly() + { + return View(); + } + } +} diff --git a/samples/MvcSample.Web/Areas/Travel/Views/Flight/Fly.cshtml b/samples/MvcSample.Web/Areas/Travel/Views/Flight/Fly.cshtml new file mode 100644 index 0000000000..ed15ba423b --- /dev/null +++ b/samples/MvcSample.Web/Areas/Travel/Views/Flight/Fly.cshtml @@ -0,0 +1,33 @@ +@using MvcSample.Web.Models +@model User +@{ + Layout = "/Views/Shared/_Layout.cshtml"; + ViewBag.Title = "This is the FLY action"; +} + +
+

ASP.NET

+

ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.

+

Learn more »

+
+
+
+

Getting started

+

+ ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that + enables a clean separation of concerns and gives you full control over markup + for enjoyable, agile development. +

+

Learn more »

+
+
+

Get more libraries

+

NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.

+

Learn more »

+
+
+

Web Hosting

+

You can easily find a web hosting company that offers the right mix of features and price for your applications.

+

Learn more »

+
+
diff --git a/samples/MvcSample.Web/Startup.cs b/samples/MvcSample.Web/Startup.cs index 522edda750..7ffbe7b23b 100644 --- a/samples/MvcSample.Web/Startup.cs +++ b/samples/MvcSample.Web/Startup.cs @@ -31,6 +31,9 @@ namespace MvcSample.Web DefaultHandler = new MvcApplication(serviceProvider), }; + // TODO: Add support for route constraints, so we can potentially constrain by existing routes + routes.MapRoute("{area}/{controller}/{action}"); + routes.MapRoute( "{controller}/{action}", new { controller = "Home", action = "Index" }); diff --git a/samples/MvcSample.Web/Views/Shared/_Layout.cshtml b/samples/MvcSample.Web/Views/Shared/_Layout.cshtml index 1f7c228ce3..3377694bed 100644 --- a/samples/MvcSample.Web/Views/Shared/_Layout.cshtml +++ b/samples/MvcSample.Web/Views/Shared/_Layout.cshtml @@ -27,7 +27,10 @@ @RenderBody()
- @Model.Address + @if (@Model != null) + { + @Model.Address + }