锚标记助手在MVC 6和Angular js中不起作用

时间:2015-12-18 10:27:02

标签: angularjs asp.net-mvc-routing asp.net-core asp.net-core-mvc

我使用MVC 6和开发了一个新的ASP.NET 5项目。

我的网页数据绑定按预期工作,但是当我在项目中使用MVC 6 Anchor TagHelper时,数据绑定无法按预期工作。

 <div class="browse-movie-wrap col-lg-2 col-md-2 col-sm-3 col-xs-6" ng-repeat="movie in movies | filter:{IsPublished:true}">

CSHTML:

   {{ movie.Id }}  @*is working*@

<a asp-controller="Movie" asp-action="MovieDetail" asp-route-movieId="{{ movie.Id }}" class="browse-movie-link">
    @*this does not work*@
</div>

生成的HTML:

<div class="browse-movie-wrap col-lg-2 col-md-2 col-sm-3 col-xs-6 ng-binding ng-scope" ng-repeat="movie in movies | filter:{IsPublished:true}">

228 //id is binded

<a class="browse-movie-link" href="/Movie/MovieDetail?movieId=%7B%7B%20movie.Id%20%7D%7D">

//but not binded anchor tag helper its remains movieID

注意:代码在同一页面

我还在MVC存储库中打开了一个问题。你可以找到它here

1 个答案:

答案 0 :(得分:1)

这是你在做什么。

您正在向ASP.NET发送代码。你看到了这个问题吗?你告诉ASP.NET:

  

我的电影ID是foreach($data as $store) { if($store['id'] == '20076231') continue; $storeArray[] = array( "name" => (string)$store['name'], "id" => (string)$store['id'] ); }

所以ASP.NET需要{{ movie.Id }}并将其编码到您的网址中。

您在服务器端概念中使用客户端代码。