0

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.

snaplemouton
  • 1,459
  • 14
  • 28

2 Answers2

1

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 }
        );
Greg Ennis
  • 14,917
  • 2
  • 69
  • 74
  • It's still giving me the same result. Is there something I need to change in ApiRegistration? Currently I have context.MapRoute("ApiUtils", "api/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional }); – snaplemouton Jan 16 '14 at 17:11
  • Still not working. :s I've tried this route template and multiple others it just won't work. :x – snaplemouton Jan 16 '14 at 17:29
  • Why do you have ApiRegistration under AreaRegistration? You dont need it, thats causing problems. Remove it – Greg Ennis Jan 16 '14 at 17:38
  • How can I register the routes without AreaRegistration in my ApiRegistration? When I check my RouteTable.Routes in debugging on VS, it shows me that the Routes were registered correctly. – snaplemouton Jan 16 '14 at 17:46
  • You should have a class WebApiConfig with a method Register that gets created for you by default in any WebApi project – Greg Ennis Jan 16 '14 at 17:56
  • I don't have that. It's not an MVC4 project. If I'm not wrong it's MVC2. I'm not the one who started the project. So I don't have a WebApiConfig but I don't see how I wouldn't be able to register my routes from using AreaRegistration. When I debug, the routes are in the RouteTable and isn't the whole point of AreaRegistration to register routes in other files like my ApiRegistration file? – snaplemouton Jan 16 '14 at 18:49
0

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

snaplemouton
  • 1,459
  • 14
  • 28