0

I am writing a View which binds the angularjs scope object with the View. I have a 'Read More' link with ng-href which reference a URL but I need to change it to call a specific controller method with a Guid Id.

I have this so far

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

how do I change it to call a specific Controller method with the Id like item.Id?

Thanks for any help

 <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>

2 Answers 2

1

Use 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;
}
Sign up to request clarification or add additional context in comments.

Comments

0

To call the controller method you don't use href instead you use ngClick like:

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

1 Comment

How do you route to the MVC controller that is the c# code?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.