Reputation: 1437
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 :
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
Upvotes: 0
Views: 2019
Reputation: 4552
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.
Upvotes: 0
Reputation: 3201
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';
Upvotes: 1