2016-05-04 43 views
0

我正在写一个视图绑定与视图的angularjs范围对象。 我有一个'阅读更多'链接与ng-href引用一个URL,但我需要 来改变它调用具有Guid Id的特定控制器方法。asp.net angularjs如何点击链接和路由到控制器的方法与Id

我有这个迄今为止

<span><a ng-href="{{item.url}}">Read More</a></span> 

我如何更改它来调用特定的控制器使用方法的Id喜欢item.Id?

感谢所有帮助

<div class="table-responsive" news-listing> 
       <table style="width: 100%;" style="border-collapse: separate;"> 
        <tr style="border-bottom: 1px solid black; padding-top: 25px;padding-bottom: 25px;" ng-repeat="item in listItems"> 
         <td colspan="100%"></td> 
         <td> 
          <img ng-src="{{item.thumbnail}}" style="width: 100px; height: 75px"/> 
         </td> 
         <td style="padding-left: 25px;"> 
          <div small> 

           <span ng-bind="item.publishedDateFormated" style="font-weight: bold"></span> 
           <span style="font-weight: bold"> | </span> 
           <span ng-bind="item.headline" style="font-weight: bold"></span><br/> 
           <span ng-bind="item.teaser"></span><br/> 
           <span><a ng-href="{{item.url}}">Read More</a></span> 

          </div> 
         </td> 
        </tr> 

       </table> 
      </div> 

回答

1

使用ng-click

HTML:

<a href="#" ng-click="readMore(item.id)">Read More</a> 

的Javascript:

$scope.readMore = function(itemId) { 
    //do things here 
    openModal(); 
    alert("hello world!"); 

    //go to a new url perhaps? 
    window.location = "path/to/stuff?itemId=" + itemId; 
} 
0

要叫你不要使用href控制方法,而不是使用像ngClick

<a href="#" ng-click="yourMethodName()">Read More</a> 
+0

如何你路由到MVC控制器是C#代码? – user1250264