jworlin / mvc.routing Goto Github PK
View Code? Open in Web Editor NEWThis project forked from benjaminkeeping/mvc.routing
Register routes using attributes on your controller actions for ASP.NET MVC
This project forked from benjaminkeeping/mvc.routing
Register routes using attributes on your controller actions for ASP.NET MVC
This dll takes some of the pain away from registering routes in ASP.NET MVC (including having to alter your routes when you rename a controller !) It's on Nuget as "Mvc.Routing" So instead of registering routes like this : routes.MapRoute( "foobar route", "foo/{someParam}/bar", new { controller = "Foo", action = "Bar" } ); You can just call : Routing.Register(typeof(MvcApplication).Assembly); And then tag your controllers : public class FooController : Controller { [Get("foo/{someParam}/bar")] public ActionResult Bar(string someParam) { // whatever } } There are attributes for Get, Post, Put, Patch and Delete The attributes behave like the normal HttpGet, HttpPost (etc) attributes - ie if you tag an action as Get(), then you can't post to it You can use them in conjunction with the normal Http* attributes, for example : public class FooController : Controller { [Get("foo/new")] public ActionResult New() { // whatever } [HttpPost] public ActionResult Create(Bar bar) { // whatever } } If you don't use the HttpGet / HttpPost attributes for your actions, you can still register routes like so : public class FooController : Controller { [Route("foo/{id}")] public ActionResult View(Guid id) { // whatever } [Route("foos")] public ActionResult List() { // whatever } } Testing your routes is also pretty simple, below is an example using Mspec (Machine.Specifications) : [Subject(typeof(TestController), "Given a test controller has marked the Index method as Get")] public class when_registering_routes : register_route_context { Establish context = () => { theExpectedRouteUrl = "all/routes/are/mine"; theExpectedActionName = "Index"; theExpectedControllerName = "Test"; }; Because of = () => { Routing.Register(typeof(TestController).Assembly); theRoute = RouteTable.Routes.Select(x => x as Route).Where(x => x.Url == theExpectedRouteUrl).FirstOrDefault(); }; Behaves_like<route_should_be_registered> route_should_be_registered; } See the project specs here for more examples : https://github.com/benjaminkeeping/Mvc.Routing/tree/master/src/Mvc.Routing.Specs/registration
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.