MVC jquery image src Url.Content quotes issue -
i have js file dynamically changing image src.
this current code trying :
$("#prodfront").attr("src", '@url.content("~/order_images/campaigns/"' + campaignkey + '"/"' + id + '"/general/front.png"")'); my image located @ location :
root folder/order_images/campaigns/ 765662bd-06ec-4925-8611-f147e232a124/1/general/front.png $("#prodfront").attr("src", '@url.content("~/order_images/campaigns/ 765662bd-06ec-4925-8611-f147e232a124/1/general/front.png")'); but code goes location
http://localhost:50209/buynow/index/@url.content(%22~/order_images/ campaigns/765662bd-06ec-4925-8611-f147e232a124/1/general/front.png%22) i can view image here :
http://localhost:50209/order_images/campaigns/765662bd-06ec-4925-8611- f147e232a124/1/general/front.png can please these quotes.
thank you.
as campaignkey , id javascript variable. can't use them @url.content since execute razor engine on server side.
as workaround, can generate url using placeholder's -1 , -2 used generate url, replaced using simple string manipulation.
//generate url var url ='@url.content("~/order_images/campaigns/-1/-2/general/front.png")'; //replace placeholder url = url.replace('-1', campaignkey).replace('-2', id); //set image $("#prodfront").prop("src",url);
Comments
Post a Comment