1
Url.Action("actionName","ControllerName",new { extraData = getdata()});

getdata() is a javascript funcion and I want to use it like

public ActionResult actionName(string extraData)
{
*/ bla /*
}

Has anyone any Idea?

1
  • What do you exactly want? Like this the javascript function getdata will be executed and its result will be passed via the variable extraData to your controller... Commented Apr 24, 2013 at 13:24

1 Answer 1

1

Javascript is client side and C# is server side so that is not going to work. It looks like you're using MVC, so why not create a route for this situation? Then the url can be manipulated with javascript on the client, and your server code remains the same.

routes.MapRoute(
    "newRoute", // Route name
    "NewRoute/{extraData}", // URL with parameters
    new
        {
            controller = "ControllerName",
            action = "ActionName",
            extraData = string.Empty
        }
    );

Then on the client you may have a link as below:

<a id="myLink" href="about:blank">My Link</a>

And you can use your javascript to manipulate this link as required:

document.getElementById("myLink").href = "/NewRoute/" + getData();

I've had to make many assumptions here, so if this doesn't answer your question then you might need to add a little more detail about what you're trying to do.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.