W
W
wkololo_4ever2014-03-25 12:33:51
JavaScript
wkololo_4ever, 2014-03-25 12:33:51

How to insert JavaScript variable in Url.Action?

There is such a script

function GetNewContact() {
           var oldId = document.getElementById("idOldContact").value;
           $.ajax({
               type: "GET",
               url: '@Url.Action("NewContacts", "Home", new { idOldContact =oldId})',
               success: function(msg){
                   $('#tableBody').append(msg);
               }
           })
       }

Actually, the problem is in the line
url: '@Url.Action("NewContacts", "Home", new { idOldContact =oldId})'

I don't know how to insert the value of the oldId variable. Now it gives an error.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question