Use Separate js File And use Url Helpers in it with ASP.NEt MVC 3 and Razor View Engine

前端 未结 6 959
太阳男子
太阳男子 2020-12-15 06:22

I ask a similar question here and Darin Dimitrov answer that we can\'t use Url helper like $.ajax({ url: \'@Url.Action(\"Index\")\', . . . in sepa

6条回答
  •  一整个雨季
    2020-12-15 07:10

    The easiest way is just to create a global variable called something and just reference to it in your external JS

    var baseURL = '@Url.Action("Index")';
    

    Inside your external JS

    $.ajax({ url: baseURL + "Action"
    

提交回复
热议问题