Cessna
Cessna

Reputation: 309

use variable inside @Url.Action ()

I have this code that needs to refer to different ActionResults in the Home Controller. The ActionResut will change depending in the "num" Jquery var. But when i concatenate "num" says that the name "num" do not exist in the current context.

var num = 2;
var cat = movie;

@Url.Action(num)

$("#container").load("@Url.Action("TheAction" + num + ",Home")?category=" +   cat, function () {..more code here};

Thanks in advance.

Upvotes: 0

Views: 622

Answers (1)

Becuzz
Becuzz

Reputation: 6857

The Url.Action method runs on your server when the page is rendered. Which means your javascript variable isn't even a thing yet (nevermind that the server code is C# or VB and not javascript). If you want to change the url the client is using via javascript, you will have to build it up by hand.

Upvotes: 2

Related Questions