c# - Using Url.Action in javascript -


i trying use url.action method correctly generate required url ajax call i'm running problems when trying build routevalues, here's problem line of code:

var url = @url.action("viewfile", "default", new { itemid = $(this).data("itemid") }); 

as can see, i'm trying assign result of jquery $(this).data("itemid") itemid in routevalues.

is there way using razor syntax allow code compile?

you confusing client side server side. try this:

var url = '@url.action("viewfile", "default")?itemid=' + $(this).data("itemid"); 

when write @ razor view engine, writing instruction process on server side @ end of command. in case want add parameter in url comes javascript, so, concat on client side value url generated @url helper.

ps: assuming using default route tables.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -