Is angular routing template url support for .cshtml file in ASP.Net MVC 4 Project ?

3,534 views
Skip to first unread message

Sombir Verma

unread,
May 23, 2014, 1:54:21 AM5/23/14
to ang...@googlegroups.com

  Is angular routing template url support for .cshtml file in ASP.Net MVC 4 Project ?
 
   if yes then please guide. because when I use html page or .aspx page it load that page but when I use .cshtml page it is not loading the view.

   Thanks in advance :)

steven smock

unread,
May 23, 2014, 11:22:07 AM5/23/14
to ang...@googlegroups.com
What happens?  Does it fail to load anything at all?  Are there any errors thrown?

As I understand it, .cshtml with Razor will only help you when it is called via an MVC GET action that returns it as a "rendered" view.  

Can you try specifying the URL of the action instead, i.e. /MyController/MyView, instead of /Views/MyController/MyView.cshtml?

Sombir Verma

unread,
May 25, 2014, 6:37:58 AM5/25/14
to ang...@googlegroups.com
Thanks Steven,
but, Actually I want to load partial view with angular where no action method is there for that partial view. Would you please help me in this case ?

steven smock

unread,
May 25, 2014, 7:16:40 AM5/25/14
to ang...@googlegroups.com
Sombir,

What you will need to do is create a new folder in your site root.  I call mine "Asset."  It is within this folder that your HTML templates will go.  Just to be clear, these should simple HTML, not Razor, for reasons described above.

Next, add an IgnoreRoute() to your RoutingConfig for this folder.  This will stop MVC from thinking that you are requesting an action, and simply serve your request as content, instead.

For more, check out asp.net+mvc+routing on this group, most recently How to use ASP.NET MVC and AngularJS routing?.  There is a lot of helpful information very close by.

Best,
SS


--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/pzjrfKVsV_0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Sombir Verma

unread,
May 25, 2014, 7:52:12 AM5/25/14
to ang...@googlegroups.com
Thanks Steven,

It helped me a lot.

Thanks again :)

Muhammad Faizan

unread,
Sep 11, 2014, 8:17:36 AM9/11/14
to ang...@googlegroups.com
I am working on MVC 5 project. When I use html page it load that page but when I use .cshtml page it is not loading, the blank page appears.
$urlRouterProvider
           
.otherwise('/app/dashboard');
        $stateProvider            
           
.state('app', {
               
abstract: true,
                url
: '/app',
                templateUrl
: 'tpl/app.html'
           
})
           
.state('app.dashboard', {
                url
: '/dashboard',
                templateUrl
: 'tpl/app_dashboard.html'
           
})

if I used .cshtml file instead of html. It shows blank page. is there any way to call my .cshtml pages instead of html pages? Thanks.

steven smock

unread,
Sep 11, 2014, 8:31:15 AM9/11/14
to ang...@googlegroups.com
Hi Muhammad,

First, make sure that you have controller-actions for your views.

Next, make sure that the views load without using Angular.  So if you have a controller-action for /tpl/app_dashboard, and it returns one of your cshtml views, try loading opening something like http://localhost/tpl/app_dashboard in your web browser.  Before moving on to the Angular side, you must be sure this is working.

Once that is working, change your the template URL in your route setup to tpl/app_dashboard.  Do not put "html" on the end of it.

Good luck!
SS

--
Reply all
Reply to author
Forward
0 new messages