I need to do something like below-
function GetParentID() {
var tv = $('#treeview').data('kendoTreeView'),
selected = tv.select(),
item = tv.dataItem(selected);
var Value= (item.ID);
return Value;
}
Then i want to use the returned value like this-
<a asp-area="Marketing" asp-controller="Store" asp-action="Create" asp-route-ID="GetParentID()" class="btn btn-default">Create</a>
I have try to save the value in hidden input like this:
<input id="p_ID" type="hidden" />
then fill this input throw jQuery and it's work like this :
$('#p_ID').val(GetParentID());
but still can't pass this value as asp-route-ID how i can achieve something like that ?
I need to do something like below-
function GetParentID() {
var tv = $('#treeview').data('kendoTreeView'),
selected = tv.select(),
item = tv.dataItem(selected);
var Value= (item.ID);
return Value;
}
Then i want to use the returned value like this-
<a asp-area="Marketing" asp-controller="Store" asp-action="Create" asp-route-ID="GetParentID()" class="btn btn-default">Create</a>
I have try to save the value in hidden input like this:
<input id="p_ID" type="hidden" />
then fill this input throw jQuery and it's work like this :
$('#p_ID').val(GetParentID());
but still can't pass this value as asp-route-ID how i can achieve something like that ?
Share Improve this question edited Jul 17, 2017 at 7:29 Death-is-the-real-truth 72.3k10 gold badges57 silver badges104 bronze badges asked Jul 17, 2017 at 7:16 MoroMoro 631 silver badge8 bronze badges1 Answer
Reset to default 5Mainly asp-route-ID="321545" Tag Helpers are server side helpers and not client side
So, you can not use client side script on server side like
JavaScript: deal only with Html and CSS (Client Side)
C# + Razor + TagHelpers: are server side (executed on the server)
So, one of the ways is to send a request using a link to the server and assign the value on the server side OR is to see how link is generated on the client: /MyWeb/MyPageIndex/123545
if we can say 123545 is the asp-route-ID then you need to: call the link and change 123545 at client Example:
<a id="stest" href="/MyWeb/MyPageIndex/123545" />
$("#stest").attr("href", "/MyWeb/MyPageIndex/" + GetParentID());
you can read here: http://www.davepaquette./archive/2015/06/01/mvc-6-anchor-tag-helper.aspx