0

I want to call a controller action method from .js file. But I am getting url as a string. It is not identifying this as a controller action method? How can we sort out this issue?

      function updateBlockAsOrphan(invalidHandles) {
    debugger;
    console.log("updateBlockAsOrphan Started..................");
    var url = '@Url.Action("updateBlockAsOrphan", "OpenDrawing", new { area = "Objects" })';        
    var paramswithcomma = invalidHandles.split(rowDelimeter).join(',');
    var params = { BlockRefHandles: paramswithcomma };
    console.log("updateBlockAsOrphan inprogress with data ..................");
    $.ajax({
        type: 'POST',
        url: url,
        data: params,
        success: function (result)
        {
            debugger;
            console.log("Result -" + result.d.length);
            //console.log("REturned Value -" + result.d[0]);
            //console.log("******************************Successhhh******************");

        }
    });



}
Dev Try
  • 211
  • 2
  • 14
  • 1
    Razor code is not parsed in external files. Generate the url in the main view (set it as a global variable that can be read in the external file, or pass it to the function in the external file –  Jul 08 '16 at 10:35
  • [How do I make JS know about the application root?](http://stackoverflow.com/questions/34360537/how-do-i-make-js-know-about-the-application-root) – Shyju Jul 08 '16 at 10:48
  • Yes.. What you said is absolutely correct. I got the solution. I passed the controller action method as a parameter to the js function. it works fine... :) – Dev Try Jul 11 '16 at 03:53

0 Answers0