Proper MVC url when using javascript

When using javascript and performing any redirect or trying to hit any url from javascript, remember to make sure the url will work when deployed to server environments (not just localhost). Use:

Use:

  var url = '@Url.Action("ActionName", "ControllerRootName", new RouteValueDictionary { { "area", "MyArea" } })' ;

OR:

 var url = "@Html.Raw(Url.Action("ActionName", "ControllerRootName", new RouteValueDictionary { { "area", "MyArea" } })  )";

DON’T USE:

var url = "/MyArea/ControllerRootName/ActionName";

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s