razor - Javascript Variable in Url.Content -


i have javascript variable called locid trying use part of url setting data-url of div follows:

data-url='@url.content("~/catalogue_items/itemsactionviewpartial/")@model.catitemid?locationid=locid&asyncupdateid=catalogue-view'> 

i know can't throw locid in string have done in sample code put there illustrate need javascript variable be. how can achieve this??

you cannot use javascript variable directly attribute. workaround can reorder parameters of url , setting javascript variable in script tag.

<button id="mybutton" data-url='@url.content("~/catalogue_items/itemsactionviewpartial/")@model.catitemid?asyncupdateid=catalogue-view'></button> 

i have reordered url parameters here. location parameter set following script. place script after button element.

<script> var button = document.getelementbyid('mybutton'); var url=button.getattribute('data-url'); url+="&locationid=" + locid; button.setattribute('data-url',url); </script> 

Comments

Popular posts from this blog

ubuntu - How to disable Kernel Module Signing in linux -

java - Ebean enhancement ignores a model -

How to combine associative arrays in bash? -