Asp.Net Mvc Url.Action in external js file?

后端 未结 5 1894
再見小時候
再見小時候 2020-11-27 14:57

In external js file, I cant use

url = \"@Url.Action(\"Action\", \"Controller\")\" 
//url output : @Url.Action(\"Action\", \"Controller\")
//I get IllegalPat         


        
5条回答
  •  独厮守ぢ
    2020-11-27 15:41

    You can use Hidden fields to do the same (on Master/Individual views).

    View page:

    @Html.Hidden("commonUrlTrack", Url.Action("Action_Method_Name", "Controller_Name"))
    
    
    

    JS File:

    function commonFunction() {
        var url = $("#commonUrlTrack").val();        
        alert(url);        
    }
    

提交回复
热议问题