Reputation: 11
I am using AngularJs
in Asp.Net mvc 4
. I would like to use the template in $routeProvider
instead of templateUrl
I wan to use this one
$routeProvider.when('/url', { template: '/view/page.html',controller: 'myCtrl' })
Instead of this one
$routeProvider.when('/url', { templateUrl: '/view/page',controller: 'myCtrl' })
I don't want to create methods in controller(that only contains return PartialView()) every time I need to implement a page. Is it possible?
Thanks.
Upvotes: 1
Views: 803
Reputation: 8670
If I understand your question correctly, you're trying to load the html template without having to use a controller.
To do this just create a new folder in your web project called Templates and then in your RouteConfig.cs add a line to ignore this folder like this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("Templates/{filename}.html");
...
}
Then in angular you can use the template url and get your file:
$routeProvider.when('/url', { templateUrl: '/templates/page.html',controller: 'myCtrl' })
Angular will be able to use your template and you won't need a controller.
Upvotes: 4