I’m working on a site and I’m new to MVC3 Framework. I’m coming from a place where writing URL’s is very simple href="some/web/page.html" but now with the MVC3 URLs are more complex.
By complex I mean are more involved to write. href="@Url.Action("index", "Home")" that requires hitting the shift key multiple times which is tiresome and redundant for someone coming from href="some/web/page.html" only hitting shift twice for that.
And the site I’m working on is using areas which adds another level of complexity to the URL.
href="@Url.Action("index", "area", new { area = "some_area})"
I’m working on a 100+ page site. Writing these @Action.Url() is becoming boring and irritating. Is there something I can do to cut out the redundancy?
You can make some extension methods like Kazi explains here :
http://weblogs.asp.net/rashid/archive/2009/04/01/asp-net-mvc-best-practices-part-1.aspx
Something like this :
You can also use David Ebbo MVC T4 template for generating helper methods :
http://blogs.msdn.com/b/davidebb/archive/2009/06/01/a-buildprovider-to-simplify-your-asp-net-mvc-action-links.aspx
http://blogs.msdn.com/b/davidebb/archive/2009/06/26/the-mvc-t4-template-is-now-up-on-codeplex-and-it-does-change-your-code-a-bit.aspx
http://mvccontrib.codeplex.com/wikipage?title=T4MVC_doc&referringTitle=T4MVC
Hope this helps