I found a very helpful article showing how to use Razor partials (cshtml) with aurelia. However, I could not get the code to run and learned from RobEisenberg comment that
ConventionalViewStrategy.convertModuleIdToViewUrl
had been deprecated. He commented "You want to use the ViewLocator service." I followed the gitHUb project and could not see that it was directly relevant to my using with MVC5 and Razor Partials. So I am confused.
This is the example main.js file that I was hoping I could tweak in order to route aurelia to the Home/Index/Index.cshtml instead of 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));
}
Can anyone tell me how to set up aurelia in an MVC5 project to use .cshtml instead of .html templates? I am using Typescript and VS2015
I just successfully followed the approach mentioned at 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());
}
来源:https://stackoverflow.com/questions/37870145/customizing-aurelia-to-use-cshtml