0

RouteConfig :

 routes.MapRoute(
                name: "Templates",
                url: "Templates/{action}/{template}",
                defaults: new {Controller = "Admin"}
                );

My state :

angular.module('uiRouterApp.newsCategories', [
        'uiRouterApp.newsCategories.Service',
        'uiRouterApp.pager.Service',
        'uiRouterApp.table.Service',
        'ui.router'
        ])
    .config(
        [
            '$stateProvider', '$urlRouterProvider',
            function ($stateProvider, $urlRouterProvider) {
                $stateProvider
                    .state('newsCategories', {
                        url: '/newsCategories/PageIndex=:PageIndex/PageSize=:PageSize/SortBy=:SortBy/SortMode=:SortMode',
                        templateUrl: '/Templates/NewsCategories/List',
                        controller: 'listCtrl'
                    });
            }
        ]
    );

AdminController :

 public class AdminController : Controller
    {
        public ActionResult NewsCategories(string template)
        {
            switch (template.ToLower())
            {
                case "list":
                    return PartialView(Url.Content("~/Views/Admin/Partials/NewsCategories/newsCategories.cshtml"));
                default:
                    throw new Exception("template not known");
            }
        }
    }

Folders :

enter image description here

Error :

GET http://localhost/Templates/NewsCategories/List 404 (Not Found) 

Why not correct partial View address?

Please see this : load file in localhost with iis7.5

Since this photo was displayed properly

2

2 Answers 2

1

If you use the url with leading slash, it will always create the url from the top level. That' is why url http://localhost/Templates/NewsCategories/List got constructed. If you remove the leading slash it always append to the current location. So if you had always same url in the whole app http://localhost/OtherApk you could use it. But if you created an url like that when the current url was http://localhost/OtherApk/something it would construct url http://localhost/OtherApk/something/Templates/NewsCategories/List which is again wrong.

So what you can do is to store the base url somewhere in a config and always append to that url.

var baseUrl = 'http://localhost/OtherApk';    
var url = baseUrl + '/Templates/NewsCategories/List';
Sign up to request clarification or add additional context in comments.

1 Comment

Hello @David. What of in the case of loading partial view in angular modal templateurl?
0

The problem is that the template URL is resolving to the Root domain, it happens because of the leading "/". On the production server that would be fine, but while debuging it can be a pain.

Try removing the leading "/":

templateUrl: 'Templates/NewsCategories/List'

Or building the full URL on the template:

templateUrl: 'http://localhost/OtherApk/Templates/NewsCategories/List'

If only the second one works, you can use a variable to hold the baseURL and change it when you are in the production server.

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.