Angular ng-include cshtml page

后端 未结 3 1342
醉梦人生
醉梦人生 2020-12-14 08:43

Im fighting with angular to make it ng-include a partial cshtml view outside of ng-view.

here is my main view:

&
相关标签:
3条回答
  • 2020-12-14 09:18

    When dealing with MVC and AngularJS, just as long as you follow any defined route(s) {Controller}/{Action}... pattern, then you should be OK. Remember you're no longer really dealing with pages URL here, but rather actions.

    You can also define a $routeProvider in an app.js file, in a similar fashion:

        app.config(function ($routeProvider) {
            $routeProvider
                .when('/login',
                    {
                        controller: 'LoginController',                        
                        templateUrl: 'http://mysite/Account/Login'
                    })
                 .when('/register',
                    {
                        controller: 'RegisterController',                        
                        templateUrl: 'http://mysite/Account/Register'
                    })                 
                  .when('/main',
                    {
                        controller: 'HomeController',                              
                        templateUrl: 'http://mysite/Home/Index'
                    })
                  .otherwise({ redirectTo: '/main' });
    });    
    
    0 讨论(0)
  • 2020-12-14 09:20

    To call partial view in asp.net mvc5 using angular js, write this way:

    <ng-include src="'@Url.Action("method_name", "Controller_name")'"></ng-include> 
    

    and it also remember your controller method must return this way:

     return PartialView("~/Views/Angular/TableAdd.cshtml");
    

    Happy coding.

    0 讨论(0)
  • 2020-12-14 09:32

    ng-include evaluates an expression, make sure if you're looking to load a path directly you use two sets of quotation marks.

    <div ng-include="'Home/Template/login'"></div>
    
    0 讨论(0)
提交回复
热议问题