blazor

Are there any Pitfalls to this approach which I am not seeing

我与影子孤独终老i 提交于 2021-01-28 12:59:12
问题 Service Registration services.AddScoped(typeof(PageStorageService<>), typeof(PageStorageService<>)); Service Declaration public interface IStoredPage<T> { T PageState { get; set; } } public class PageStorageService<T> : IStoredPage<T> { public T PageState { get; set; } } Usage in CounterPage @page "/counter" @using BlazorApp1.Data <h1>Counter</h1> <p>Current count: @currentCount</p> @inject PageStorageService<Counter> StorageService <button class="btn btn-primary" @onclick="IncrementCount"

Use injected service from JS code to static Blazor method

拜拜、爱过 提交于 2021-01-28 12:28:58
问题 I have an app that uses a jQuery lib to show 'confirmation' dialogs. When a user clicks 'OK' or 'Cancel' on the dialog, then first a callback is made to my Javascript code. From there I do a call to a Blazor method, based on the decision the user made. This all looks something like this: My js code: $('.alert-yesno).on('click', function() { // For simplicity I immediately call the Blazor method DotNet.invokeMethodAsync('[Assembly name]', 'DoSomething') .then(data => { // do something... }); }

Dynamically create CascadingValue in custom base component class

雨燕双飞 提交于 2021-01-28 11:09:40
问题 I'm using a custom base component class from which every custom page inhertits from. I do not have any razor code, because it won't be templated in my my base component class - it is only supposed to contain some base logics and intialization stuff. Now i want do wrap around a cascading value, because on any component/page which will be nested within any child level should get access to a property value of my base class. How can i do this, i tried to fake some childContent on the base

How to get EditContext.Validate() to work when binding EditForm to an array

会有一股神秘感。 提交于 2021-01-28 10:21:50
问题 I created an EditForm wrapping a table like so: **Index.razor** @using System.ComponentModel.DataAnnotations; <EditForm @ref="Form" Model="vms" OnSubmit="Submit"> <DataAnnotationsValidator></DataAnnotationsValidator> <table class="table"> <thead> <tr> <th>Code</th> </tr> </thead> <tbody> @foreach (var vm in vms) { <tr> <td> <InputText @bind-Value="vm.Code"></InputText> <ValidationMessage For="@(() => vm.Code)"></ValidationMessage> </td> </tr> } </tbody> </table> <input type="submit" class=

How do I make a javascript function available after the document is loaded in Blazor?

ぃ、小莉子 提交于 2021-01-28 09:02:12
问题 Without using Blazor, <script> $(document).ready(function () { alert('hello') // what you want to initialize }); </script> With Blazor, do I just put the above script in wwwroot/index.html and call it from Blazor razor page in OnInitializedAsync method? 回答1: In Blazor Server App you can add a script tag (in _Host.cshtml file) to your JavaScript file like this: <script src="_framework/blazor.server.js"></script> <script src="exampleJsInterop.js"></script> Your JS file should be placed in the

Blazor WebAssembly template not found in Blazor new project

只愿长相守 提交于 2021-01-28 05:36:52
问题 I have installed dotnet SDK 3.1.201 to Microsoft Visual Studio Professional 2019 Version 16.5.4 and I installed this template dotnet new -i Microsoft.AspNetCore.Components.WebAssembly.Templates::3.2.0-preview5.20216.8 after that I statred to create a new Blazor project in VS just only contains the Blazor Server App template I didn't find the Blazor WebAssembly App template what is wrong with all steps that I have done. 回答1: I have the same problem when I tried to install the template, my

Blazor - Global Objects - Use SessionStorage?

≯℡__Kan透↙ 提交于 2021-01-28 02:24:28
问题 I have a Blazor app, with mulitple pages and components etc. I need to persist & pass a global object between pages and components. Say for example, a CUSTOMER object that will be read and updated between pages. What is the best way to do this? Use SessionStorage? https://docs.microsoft.com/en-us/aspnet/core/blazor/state-management?view=aspnetcore-3.1 Or use a Service like this? StateManager? https://blog.jeremylikness.com/blog/blazor-state-management/ Thoughts? Thx in advance 回答1: The first

Blazor /Pages folder required for all pages/views?

蹲街弑〆低调 提交于 2021-01-28 01:08:47
问题 Using the default Blazor helloworl app, i copied the FetchData.razor page to a separate, custom folder. The result: The page is not being rendered properly (the page is taking up the whole screen / the navigation menu is gone). Question: Do blazor pages/views must be in the /Pages folder? 回答1: You are free to put components in whatever folders you wish, the Pages folder is just what comes with the template. But you will notice in the default templates, the Pages folder has a file called

如何在 Blazor WebAssembly中 使用 功能开关

邮差的信 提交于 2021-01-27 22:39:57
微软Azure 团队开发的 功能管理 (Feature Management) 包 Microsoft.FeatureManagement可用于实现 功能开关,可以通过 功能开关 特性动态的改变应用程序的行为而不需要改变任何的业务逻辑代码。关于功能开关的更多功能请看Edi Wang的B站视频,长按小程序码进入观看 这篇文章的重点是介绍如何在Blazor WebAssembly项目中实现功能开关。 通过 NuGet 安装 Microsoft.FeatureManagement ,可通过 Visual Studio 2019 下的 NuGet Package Manager 可视化管理界面 或者 通过 .NET CLI 命令行工具输入如下命令。 dotnet add package Microsoft.FeatureManagement 为了能够在项目中用上 功能管理 ,需要在 ConfigureServices 方法下进行 service 注入,如下代码所示: 有一点要注意: 功能管理 中的 功能开关 读取的值来自于配置文件,如果你想让 功能开关 的值来源于 Configuration 文件的不同节点,必须在 service 注册时单独指定一下。 为了能够在 Blazor Wassembly中用上 功能管理(feature management) ,需要通过依赖注入的方式将其注入到

How can I publish a blazor client/server app to a linux web server? Don't have access to ssh and dotnet publish doesn't give an index.html

爷,独闯天下 提交于 2021-01-27 22:16:03
问题 I've built a blazor app that has no issues at the moment. When I call "dotnet publish -c Release" I get a published project, except the output is an executable file that ubuntu picks up as an octet-stream or something along the lines. If I run it, it just opens the server on localhost:5000. Copying this to my web server through cpanel did nothing -- even trying to test out a generic blazor Wasm app and publishing it gave me an index.html, but it would never actually load anything when I