I've an anchor element with the attribute of asp-controller and
asp-action. I've a javaScript variable, named g_id that will call the getIdFromUrl function. This function will retrieve the id appended at the end of the url.
/User/Account/5
For example, this function will retrieve the value of 5 from the URL. I want to assign this value to the asp-route-id. However, I am unable to do so.
<a asp-action="ActivityPrice" asp-controller="Activity" asp-route-id = "g_id" class="btn btn-primary" >
Add Activity Price
var g_id = getIdFromURL();
function getIdFromURL() {
var urlArray = window.location.href.split('/');
var id = urlArray[urlArray.length - 1];
return id;
}
Asp.Netwill renderasp-tag helpers before giving the HTML code to the browser. There shouldn't be anyasp-tags in the HTML you view in the browser.asp-action,asp-controller, andasp-route-will all compile into a singlehreftag for an anchor element. Rather than looking to change theasp-route-idtag, look to change thehreftag.