Asp.net mvc UI路由器未使用Asp.net Mvc中的templateurl正确呈现孩子
我提到过这样的国家Asp.net mvc UI路由器未使用Asp.net Mvc中的templateurl正确呈现孩子,asp.net-mvc,angularjs,angular-ui-router,Asp.net Mvc,Angularjs,Angular Ui Router,我提到过这样的国家 $stateProvider .state('dashboard', { url: "/dashboard", views: { content: { templateUrl: "/dashboard/index" } } }).state('accounts', { url: "/accounts",
$stateProvider
.state('dashboard', {
url: "/dashboard",
views: {
content: { templateUrl: "/dashboard/index" }
}
}).state('accounts', {
url: "/accounts",
views: {
'content': { templateUrl: "/accounts/index" }
}
})
.state('accounts.add', {
url: "/add",
views: {
'content': { templateUrl: "/accounts/add" }
}
});
public class AccountsController : Controller
{
//
// GET: /Accounts/
public ActionResult Index()
{
return Request.IsAjaxRequest() ? (ActionResult)PartialView("_Icons") : View();
}
public ActionResult Add()
{
return Request.IsAjaxRequest() ? (ActionResult)PartialView("_Add") : View();
}
}
GET http://localhost:2060/accounts/index 200 OK 2ms
GET http://localhost:2060/accounts/add 200 OK 5ms
而且URL是
<a class="list-group-item submenu" ui-sref="accounts">Service Users</a>
<a class="list-group-item submenu" ui-sref="accounts.add">Add User</a>
但是,每当我向状态accounts.add
发出请求时,它总是调用accounts
状态。并将\u图标
视图呈现为\u icons.cshtml
,它只是一个局部视图。我可以在firebug中看到url已被调用,但从未被呈现。为什么
firebug的输出是这样的
$stateProvider
.state('dashboard', {
url: "/dashboard",
views: {
content: { templateUrl: "/dashboard/index" }
}
}).state('accounts', {
url: "/accounts",
views: {
'content': { templateUrl: "/accounts/index" }
}
})
.state('accounts.add', {
url: "/add",
views: {
'content': { templateUrl: "/accounts/add" }
}
});
public class AccountsController : Controller
{
//
// GET: /Accounts/
public ActionResult Index()
{
return Request.IsAjaxRequest() ? (ActionResult)PartialView("_Icons") : View();
}
public ActionResult Add()
{
return Request.IsAjaxRequest() ? (ActionResult)PartialView("_Add") : View();
}
}
GET http://localhost:2060/accounts/index 200 OK 2ms
GET http://localhost:2060/accounts/add 200 OK 5ms
这是当我单击ui sref=“accounts.add”并最终呈现索引操作时发生的情况。有人能告诉我为什么会这样吗?这不应该发生。ui路由器中是否有我遗漏的常规内容?我已经创建了一个显示/解释该问题的文档
关键是,该子状态:
.state('accounts.add', {
url: "/add",
views: {
'content': { templateUrl: "/accounts/add" }
}
与其父项具有相同的视图名称:“内容”。事实上,这并不意味着他们的目标是相同的观点。否-子级正在父级中搜索具有相同名称的视图content
父状态(帐户
)的目标是Index.html(在ASP.NET MVC/home/中):
如何定位根ui view=“content”
(index.html)的方法是使用绝对命名。在我使用的插入状态中:
.state('accounts.insert', {
url: "/insert",
views: {
'content@': { templateUrl: "accounts.insert.tpl.html" }
}
其中,在视图名称'content@
中,@
i是指向根的方式。有关更多详细信息,请查看文档:
views: {
////////////////////////////////////
// Relative Targeting //
// Targets parent state ui-view's //
////////////////////////////////////
// Relatively targets the 'detail' view in this state's parent state, 'contacts'.
// <div ui-view='detail'/> within contacts.html
"detail" : { },
// Relatively targets the unnamed view in this state's parent state, 'contacts'.
// <div ui-view/> within contacts.html
"" : { },
///////////////////////////////////////////////////////
// Absolute Targeting using '@' //
// Targets any view within this state or an ancestor //
///////////////////////////////////////////////////////
// Absolutely targets the 'info' view in this state, 'contacts.detail'.
// <div ui-view='info'/> within contacts.detail.html
"info@contacts.detail" : { }
// Absolutely targets the 'detail' view in the 'contacts' state.
// <div ui-view='detail'/> within contacts.html
"detail@contacts" : { }
// Absolutely targets the unnamed view in parent 'contacts' state.
// <div ui-view/> within contacts.html
"@contacts" : { }
// absolutely targets the 'status' view in root unnamed state.
// <div ui-view='status'/> within index.html
"status@" : { }
视图:{
////////////////////////////////////
//相对目标//
//目标为父状态ui视图的//
////////////////////////////////////
//相对地以该状态的父状态“联系人”中的“详细信息”视图为目标。
//在contacts.html中
“细节”:{},
//相对地以该状态的父状态“contacts”中的未命名视图为目标。
//在contacts.html中
"" : { },
///////////////////////////////////////////////////////
//使用“@”的绝对目标定位//
//以该状态或祖先中的任何视图为目标//
///////////////////////////////////////////////////////
//绝对针对此状态下的“info”视图“contacts.detail”。
//在contacts.detail.html中
"info@contacts.detail" : { }
//绝对以“联系人”状态下的“详细信息”视图为目标。
//在contacts.html中
"detail@contacts" : { }
//绝对以父“联系人”状态的未命名视图为目标。
//在contacts.html中
“@contacts”:{}
//绝对以根未命名状态的“状态”视图为目标。
//在index.html中
“状态@”:{}
因此,当/account
呈现时,它会在具有内容的外部ui视图中搜索内容
视图,我理解正确。是这样吗?你的想法很好。我只是澄清我的理解。你是对的:我会这样说:State定义在其父视图中定义的视图…除非使用更精确的(@)命名。这样,我们甚至可以以当前状态定义的视图为目标(例如。hint@accounts可以在其中一个*主帐户视图*中定义)*但是是的,现在您清楚地了解了;)享受ui路由器;)