1

I have problem with routing inside ASP.NET application. When I move my angularJS outside of ASP.NET MVC it's working fine (on XAMPP) but when I run it inside Visual Studio 2013 my Index page is blank. I really don't know where's the problem... Does someone knows where's the problem?

Here is code that I am using:

angularJS routing script:

var app = angular.module('contactsManager', ['ngRoute']);
app.config(function ($routeProvider) {
    $routeProvider
        .when('/contacts',
            {
                controller: 'ContactsController',
                templateUrl: 'templates/contacts.html'
            })
        .when('/add-contact',
            {
                controller: 'ContactAddController',
                templateUrl: 'templates/addContact.html'
            })
        .when('/edit-contact/:contactId',
            {
                controller: 'ContactEditController',
                templateUrl: 'templates/editContact.html'
            })
        .when('/display-contact/:contactId',
            {
                controller: 'ContactDetailsController',
                templateUrl: 'templates/displayContact.html'
            })
        .otherwise({ redirectTo: 'templates/contacts' });
});

ASP.NET Home Controller:

public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Templates()
        {
            return PartialView();

        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }

ASP.NET Route Config:

public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute("templates", "templates/{action}/{name}",
             new { controller = "Home", action = "Templates", name = "" }
            );
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
2
  • How do you deploy your application? Do you run it from IIS Express? What URL does it have? Also you need to sync routing configuration in angular and ASP .Net. Commented Dec 23, 2014 at 17:21
  • I run it on default IIS server that comes with ASP.NET Visual Studio 2013. I don't know where's the problem. How do I sync routing configuration with angular and asp.net ? @oryol Commented Dec 23, 2014 at 17:29

1 Answer 1

2

On the client side you load templates from urls like templates/{something}.html. But on the server side your routing is configured as templates/{action}/{name}. As you see it doesn't have .html suffix and has one more part: {name}. Also you don't have name parameter in your actions. Do you really need it? I suggest you try templates/{action}.html routing template on the server side.

Sign up to request clarification or add additional context in comments.

1 Comment

your suggestion worked well for me. Thank you for help

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.