How can you point directly to a .cshtml view from javascript file?
For example why can’t I use a .cshtml view with angular.js?
like in this example:
.directive('encoder', ($timeout) => {
return {
restrict: 'E',
transclude: true,
scope: 'isolate',
locals: { service: 'bind' },
templateUrl: 'encoderTemplate.cshtml' // <-- that's not possible?
}
});
It’s of course possible to have an action method that returns whatever you want, but I’m curious if it’s possible to reference directly to the razor view.
As mentioned in a comment, you can’t serve up .cshtml files directly, However, you can use a controller to render the content if you so choose:
Then reference it like you would with
@Url.Action:From Comment
If you have most of the JavaScript code outside of something that has Razor access (e.g. external .js file) you can still take advantage of the Url builder, just have to do so a little differently. For instance, I may do something like:
~/Views/Template/Index.cshtml
Index.cshtml (or whatever is any view)