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

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -