Saturday, May 11, 2013

ASP.NET MVC IDE-friendly URL

Instead of using hardcoded url or Url.Content...

var theUrl = '@Url.Content("~/MyPeople/OffCycleCompensation/IsEligible")';        
 
        $.ajax({
            url: theUrl,
            type: 'POST',
            async: false,
            data: { personID : personID },
            success: function (data) {


...use IDE-friendly URL helpers to make maintenance programming easier, e.g. use Url.RouteUrl:


var theUrl = '@Url.RouteUrl("AreaRoute", new { area = "MyPeople", controller= "OffCycleCompensation", action="IsEligible" })';        
 
        $.ajax({
            url: theUrl,
            type: 'POST',
            async: false,
            data: { personID : personID },
            success: function (data) {
 


Advantage being, the code is more navigable, just hold Ctrl and press left click on IsEligible, the IDE will bring you to IsEligible method. If you are using ReSharper, just position the cursor on IsEligible and press Ctrl+B



Little things that works wonders



Happy Coding! ツ

No comments:

Post a Comment