Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass variable as parameter to Url.Action in javascript

I am passing parameters to @Url.Action like this:

function showHistory()
{

myId= $("#id").val();
    //alert(myId);
    actionDialog.load("@Url.Action("ActionHistoryAjax", new {id = myId, sort = "abc"})", function   () {
        actionDialog.dialog('open');
    });
}

But gives error "the name myId does not exist in the current context".

How i can pass the variable?

I solved this, this is the solution:

function showHistory()
{

myId= $("#id").val();
//alert(myId);
actionDialog.load("@Url.Action("ActionHistoryAjax", new {id = "_Id", sort = "abc"})".replace("_Id", DeviceID), function   ()     {
 actionDialog.dialog('open');
});
}
like image 856
Altaf Sami Avatar asked May 30 '13 11:05

Altaf Sami


People also ask

Is there a way to pass javascript variables in URL?

Syntax: var URLSearchParams = URL. searchParams; Example 1: This example adds the parameter by using append method.

How do you pass dynamic values in URL action?

How do you pass dynamic values in URL action? You can concat the client-side variables with the server-side url generated by this method, which is a string on the output. Try something like this: var firstname = "abc"; var username = "abcd"; location. href = '@Url.


1 Answers

I solved it by using this:

function showHistory()
{
    myId= $("#id").val();
    actionDialog.load("@Url.Action("ActionHistoryAjax", new {id = "_Id", sort = "abc"})".replace("_Id", DeviceID), function   ()     {
        actionDialog.dialog('open');
    });
}
like image 90
Altaf Sami Avatar answered Oct 02 '22 23:10

Altaf Sami