3
votes

I’m quite new to Aurelia. I have managed to get Aurelia up and running within an ASP.NET MVC application, and now I want to fetch an Aurelia element view using an ASP.NET MVC action. I have seen some examples using either useView, getViewStrategy or ViewLocator but even though the examples mention ASP.NET MVC or Razor, they all appear to use static HTML.

My findings:

useView

@useView('/Issue/EditIssueHtml') 
export class EditIssue {

Apperently useView only support static HTML: Unhandled rejection Error: Load timeout for modules: template-registry-entry!/Issue/EditIssueHtml,text!/Issue/EditIssueHtml

getViewStrategy

export class EditIssue {
    getViewStrategy() {
        return '/Issue/EditIssueHtml';
    }
}

The method only works for the application root (it is never called for elements). However, using it with the application root and an ASP.NET MVC action throws the same error as when using useView suggesting that only static HTML is supported.

ViewLocator

ViewLocator.prototype.convertOriginToViewUrl = (origin: Origin) => {
  var moduleId: string = origin.moduleId;
  var name = moduleId.split('/')[moduleId.split('/').length - 1].replace('ViewModel', 'View').replace('.js', '').replace('.ts', '');
  console.log('ViewLocator: ' + name);
  if (name !== 'edit-issue') {
    return `${name}.html`;
  }
  return "/Issue/EditIssueHtml";
}

Same error as with useView.

I found a question at Aurelia server side views: Adding auth header to http download request of view/viewmodel where the questioner claims to have created a working solution based on the Aurelia documentation at http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/app-configuration-and-startup/9, but the documentation does not mention anything about server side views.

Have I missed something or does Aurelia not support server side views?

1
My own conclusion is that server-side rendering is not possible with Aurelia. I stumbled across the aurelia / skeleton-server-render project at GitHub (github.com/aurelia/skeleton-server-render/issues/1), and the reason for creating this project must be because it is not possible. Sadly, however, it appears that the project is dead. - halvorsen

1 Answers

1
votes

From my professional life with Aurelia i do not recommend using it with MVC and Razor.

I have tried to do this for almost a year now and i just cant get past the npm stuff in visual studio.

My suggestion to is to avoid Aurelia with server side rendering. It will only haunt you in your sleep every night.

In my long career with Aurelia i have spent almost 2 days making SPA and this works great.

If i were you i would take the SPA road.

To answer your question it is not even possible to make serverside rendering using Aurelia.

Good luck.