2016-05-04 45 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