1

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.

4
  • do you want the content within the /view/page.html to be displayed or simply you want to show like /view/page.html printed Commented Aug 8, 2014 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. Commented Aug 8, 2014 at 5:35
  • @NidhishKrishnan I want to implement the content in /view/page.html. Commented Aug 8, 2014 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 Commented Aug 8, 2014 at 7:37

1 Answer 1

4

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.

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

Comments

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.