Asp.net mvc “加载”;“局部视图”;使用localhost-iis7.5-AngularJs中的模板Url
路线图:Asp.net mvc “加载”;“局部视图”;使用localhost-iis7.5-AngularJs中的模板Url,asp.net-mvc,angularjs,url,iis-7.5,asp.net-mvc-partialview,Asp.net Mvc,Angularjs,Url,Iis 7.5,Asp.net Mvc Partialview,路线图: routes.MapRoute( name: "Templates", url: "Templates/{action}/{template}", defaults: new {Controller = "Admin"} ); 我国: angular.module('uiRouterApp.newsCategories', [ 'uiRou
routes.MapRoute(
name: "Templates",
url: "Templates/{action}/{template}",
defaults: new {Controller = "Admin"}
);
我国:
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'
});
}
]
);
管理员控制器:
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");
}
}
}
文件夹:
错误:
GET http://localhost/Templates/NewsCategories/List 404 (Not Found)
为什么不更正部分视图地址
请看这个:
由于此照片显示正确如果使用带前导斜杠的url,它将始终从顶层创建url。这就是url
http://localhost/Templates/NewsCategories/List
已构建。如果删除前导斜杠,它将始终附加到当前位置。因此,如果你在整个应用程序中始终使用相同的urlhttp://localhost/OtherApk
您可以使用它。但是如果您在当前url为http://localhost/OtherApk/something
它将构造urlhttp://localhost/OtherApk/something/Templates/NewsCategories/List
这又错了
因此,您可以将基本url存储在配置中的某个位置,并始终附加到该url
var baseUrl = 'http://localhost/OtherApk';
var url = baseUrl + '/Templates/NewsCategories/List';
问题是模板URL解析到根域,这是因为前导“/”导致的。在生产服务器上,这很好,但在调试时可能会很痛苦 尝试删除前导“/”: 或在模板上构建完整URL:
templateUrl: 'http://localhost/OtherApk/Templates/NewsCategories/List'
如果只有第二个有效,则可以使用变量保存baseURL,并在生产服务器中更改它。works?。你好,大卫。在角度模式下加载局部视图时,会发生什么情况?
templateUrl: 'http://localhost/OtherApk/Templates/NewsCategories/List'