Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
    
do you want the content within the /view/page.html to be displayed or simply you want to show like /view/page.html printed –  Nidhish Krishnan Aug 8 '14 at 5:31
    
Mixing server side and client side routing, or even trying to will lead to a lot of pain. You may need to revisit some angular js fundamental - specifically to understand that there is no server side dependency when working within angular. –  Abhinav Gujjar Aug 8 '14 at 5:35
    
@NidhishKrishnan I want to implement the content in /view/page.html. –  user3916743 Aug 8 '14 at 7:33
    
I am not trying to mix their routing, i am just trying not to use any web controllers just to render the page –  user3916743 Aug 8 '14 at 7:37

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.