I am using angularJS with ASP.NET
. When I run my Web application, all links are working and there is no 500 error.
But when I refresh page I got 500 error like this one:
The partial view 'Contacts' was not found or no view engine supports the searched locations. The following locations were searched:
I am using angularJS controller to load template from ./templates folder and angularJS is doing that job very well...
Does someone knows why I am getting this error and how to fix it?
Also inside View folder there is only Index.cshtml file because because I load templates from ./templates directory
Here is RouteConfig.cs code:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("templates", "templates/{action}.html",
new { controller = "Home", action = "Templates", name = "" }
);
routes.MapRoute("contacts","contacts",
new { controller = "Home", action = "Contacts", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
Controller class:
public ActionResult Index()
{
return View();
}
// ActionResult prikazan ispod slu?i da bi angularJS
// mogao lodati HTML template u template folderu
public ActionResult Contacts()
{
return PartialView();
}
public ActionResult Templates()
{
return PartialView();
}
and here is angularJS route config:
app.config(function ($routeProvider, $locationProvider) {
$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'
})
.when('/bookmarked-contacts',
{
controller: 'ContactsController',
templateUrl: 'templates/bookmarkedContacts.html'
})
.when('/search-contacts',
{
controller: 'SearchContactsController',
templateUrl: 'templates/searchContacts.html'
})
.otherwise({ redirectTo: '/contacts' });
$locationProvider.html5Mode(true);
});
See Question&Answers more detail:
os