2016-06-12 29 views
1

更改asp.net核心TagHelpers使用Javascript

<a id="continue-link" asp-controller="Account" asp-action="Register" asp-route-id="1">Continue </a> 
在我的asp.net核心应用

,编译时产生这个网站:

<a href="/Account/Register/1" id="continue-link">Continue </a> 

我怎样才能改变从JavaScript asp-route-id值?我尝试了$().attr,但没有被识别。

+0

你试过['$().prop()'](http://api.jquery.com/prop/)吗? – NightOwl888

回答

3

您必须在生成的html中更改您的href属性。

您可以通过创建您的href属性,将其拆分为数组,然后更改数组中的值并将其重新连接到具有分隔符的一个字符串中,然后替换元素中的href属性来实现此目的。

代码示例:

var $link = $('#continue-link'); 
var href = $link.attr('href').split('/'); 
href[3] = 4; //here you set your new asp-route-id value 
$link.attr('href', href.join('/')); 

检查这个codepen来看看它是如何工作的。

+0

5分钟前我做了什么:D –

+0

啊,所以我迟到了;) – Sousuke