I have created a new Blazor WebAssembly standalone project. I'd like to be able to insert this app into views in my current ASP.NET MVC 5 project, like how React can be inserted into any DOM element in an HTML page.
I think that ASP.NET Core has better integration with Blazor but upgrading is probably not possible. So I think my only chance of integrating Blazor would be to have it produce static files, copy these files to my hosted ASP.NET MVC 5 app on IIS, and then load scripts from these files in my views. e.g. have a div with id "app" and then load blazor.webassembly.js
to put the Blazor app into this div.
However, Blazor only seems to work when I'm hosting the published files with IIS.
When I try to open the published index.html
file directly in the browser, Blazor says than an unhandled error has occurred and produces this warning in the console: Loading failed for the <script> with source “c:/Tracker/Development/TrackerBlazor/bin/Release/net5.0/browser-wasm/publish/wwwroot/_framework/blazor.webassembly.js”
.
What might be the issue? Could there be other solutions for using Blazor in my ASP.NET MVC 5 application?
This is the index.html
file:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>TrackerBlazor</title>
<base href="/" />
<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
<link href="css/app.css" rel="stylesheet" />
<link href="TrackerBlazor.styles.css" rel="stylesheet" />
</head>
<body>
<div id="app">Loading...</div>
<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss"></a>
</div>
<script src="_framework/blazor.webassembly.js"></script>
</body>
</html>