我发现了一篇非常有用的文章,展示了如何在aurelia中使用Razor partials(cshtml)。但是,我无法从RobEisenberg的评论中获得运行和学习的代码
ConventionalViewStrategy.convertModuleIdToViewUrl
已被弃用。他评论说"你想使用ViewLocator服务。"我跟着gitHUb项目,看不出它与我使用MVC5和Razor Partials直接相关。所以我很困惑。
这是我希望我可以调整的示例main.js文件,以便将aurelia路由到Home / Index / Index.cshtml而不是index.html
import {LogManager} from "aurelia-framework";
import {ConsoleAppender} from "aurelia-logging-console";
import {ConventionalViewStrategy} from "aurelia-framework";
LogManager.addAppender(new ConsoleAppender());
LogManager.setLevel(LogManager.logLevel.debug);
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging();
ConventionalViewStrategy.convertModuleIdToViewUrl = function(moduleId){
var moduleName = moduleId.replace("Scripts/", "");
return `./Templates/${moduleName}`;
}
aurelia.start().then(a => a.setRoot("./Scripts/index", document.body));
}
有谁能告诉我如何在MVC5项目中设置aurelia使用.cshtml而不是.html模板?我正在使用Typescript和VS2015
答案 0 :(得分:2)
我刚刚成功地遵循了http://ilikekillnerds.com/2016/02/using-views-different-locations-aurelia/中提到的方法:
import {Aurelia, ViewLocator, Origin, Container} from 'aurelia-framework';
export function configure(aurelia: Aurelia, container: Container) {
aurelia.use
.standardConfiguration()
.developmentLogging();
ViewLocator.prototype.convertOriginToViewUrl = (origin: Origin) => {
var moduleId: string = origin.moduleId;
var moduleName = moduleId.split('/')[moduleId.split('/').length - 1].replace('ViewModel', 'View').replace('.js', '').replace('.ts', '');;
let newViewUrl = `./Templates/${moduleName}`;
console.log(newViewUrl); // e.g. ./Templates/app
return newViewUrl;
}
aurelia.start().then(() => aurelia.setRoot());
}