Question

I'm trying to make this map routing work for my .net client-server application using angularJS.

It's my first time doing map routing and angularJS so I'm having quite an hard time understanding how it works.

Basically, I have a website with Client and Server.

Solution

In this website, I'm trying to use map routing for my client to fetch data from my server which get the data from an SQL database.

Problem is, I can't seem to make this map routing work and it seems to completely ignore my map routing and instead try to GET an URL.

Map Routing not working

My question is: Why is it not working?

You can see my code here

Thank you for any help you can provide and I can edit if there is code missing in what I showed

Edit: For information, this isn't an MVC4 project but a MVC2 Or MVC3. I'm not sure as I'm not the one who started the project.

Était-ce utile?

La solution 2

I discovered the reason as to why it is not working. My map routing was actually good. The problem comes from using Visual Studio Express.

The Client and Server project doesn't build on the same IP on Express version of VS. So when I tried using my map routing, the client couldn't GET something on the server as the server was using a different IP.

To counter this, I'll be using MSBuild

Autres conseils

The URL shouldn't end with GetManual.. The Web API controller will use the HTTP method to determine which action to call. So in your $http call, replace this:

'../api/Manuals/GetManual'

with

'../api/Manuals'

And you probably have to replace this

public JsonResult GetManual(int id)
{
    var obj = this.db.GetManual(id);
    return this.JsonHelper(obj);
}

with

public Manual Get(int id)
{
    var obj = this.db.GetManual(id);
    return obj;
}

Your route config should be like this:

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top