【发布时间】:2015-02-26 16:37:19
【问题描述】:
我正在使用带有 ASP.NET 的 angularJS。当我运行我的 Web 应用程序时,所有链接都正常工作并且没有 500 错误。
但是当我刷新页面时,我收到了类似这样的 500 错误:
未找到部分视图“联系人”或没有视图引擎支持搜索到的位置。搜索了以下位置:
我正在使用 angularJS 控制器从 ./templates 文件夹加载模板,而 angularJS 做得很好......
有人知道我为什么会收到此错误以及如何解决它吗?
View 文件夹内也只有 Index.cshtml 文件,因为我从 ./templates 目录加载模板 这是 RouteConfig.cs 代码:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("templates", "templates/{action}.html",
new { controller = "Home", action = "Templates", name = "" }
);
routes.MapRoute("contacts","contacts",
new { controller = "Home", action = "Contacts", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
控制器类:
public ActionResult Index()
{
return View();
}
// ActionResult prikazan ispod služi da bi angularJS
// mogao lodati HTML template u template folderu
public ActionResult Contacts()
{
return PartialView();
}
public ActionResult Templates()
{
return PartialView();
}
这里是 angularJS 路由配置:
app.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when('/contacts',
{
controller: 'ContactsController',
templateUrl: 'templates/contacts.html'
})
.when('/add-contact',
{
controller: 'ContactAddController',
templateUrl: 'templates/addContact.html'
})
.when('/edit-contact/:contactId',
{
controller: 'ContactEditController',
templateUrl: 'templates/editContact.html'
})
.when('/display-contact/:contactId',
{
controller: 'ContactDetailsController',
templateUrl: 'templates/displayContact.html'
})
.when('/bookmarked-contacts',
{
controller: 'ContactsController',
templateUrl: 'templates/bookmarkedContacts.html'
})
.when('/search-contacts',
{
controller: 'SearchContactsController',
templateUrl: 'templates/searchContacts.html'
})
.otherwise({ redirectTo: '/contacts' });
$locationProvider.html5Mode(true);
});
【问题讨论】:
标签: asp.net asp.net-mvc angularjs