Wrox Programmer Forums
|
BOOK: Professional ASP.NET MVC 5
This is the forum to discuss the Wrox book Professional ASP.NET MVC 5 by Jon Galloway, Brad Wilson, K. Scott Allen, David Matson; ISBN: 978-1-118-79475-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET MVC 5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 8th, 2017, 06:20 AM
Registered User
 
Join Date: Feb 2017
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default hash sign # not routing

I'm using VS Community Edition, AngularJS 1.6 and Google Chrome as my browser.

In Chapter 12 the re-routing using Angular with a hash sign isn't working. There are no errors it just doesn't produce the details view on clicking the a-link.

HTML Code:
            <td>{{movie.Title}}</td>
            <td>
                <a href="#/details/{{movie.Id}}">Details</a>
            </td>
Code:
            <td>{{movie.Title}}</td>
            <td>
                <a href="#/details/{{movie.Id}}">Details</a>
            </td>[/HTML]
        $routeProvider
            .when("/list",
                { templateUrl: "/client/views/list.html" })
            .when("/details/:id",
                { templateUrl: "/client/views/details.html" })
            .otherwise(
                { redirectTo: "/list" }
            );
        //$routeProvider.html5Mode(true);
As you can see, I attempted html5Mode and removing the hash-sign but the method isn't found.

(A side issue is that I also cannot use the $http.get() shorthand as this method isn't found either.)

Thank you.
 
Old February 28th, 2017, 04:44 PM
Registered User
 
Join Date: Feb 2017
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Default

Try using this instead. Note the additional ! character. This worked for me although I have no idea why.
HTML Code:
<a class="btn btn-default" href="#!/details/{{movie.Id}}">Details</a>
Also, the book is using $http.get().success();, but that is now deprecated. Try using something like this instead.
Code:
$http.get("/api/movie").then(
            function (response) { // success
                $scope.movie = response.data;
            },
            function (response) { // failure
                $scope.movie = response.data || "Fail";
            }
        );
The Following User Says Thank You to mhirons For This Useful Post:
 
Old February 28th, 2017, 05:00 PM
Registered User
 
Join Date: Feb 2017
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your post. I'll try this at the weekend.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Hash and un-hash Mattt C# 1 August 25th, 2009 11:40 AM
URL Routing elwappo ASP.NET 3.5 Professionals 2 June 11th, 2009 01:20 AM
URL Routing elwappo ASP.NET 2.0 Professional 4 May 26th, 2009 04:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.