blazor

Blazor: A second operation started on this context before a previous operation completed

可紊 提交于 2019-12-29 08:23:04
问题 I'm creating a server side Blazor app. The following code is in the Startup.cs . services.AddDbContext<MyContext>(o => o.UseSqlServer(Configuration.GetConnectionString("MyContext")), ServiceLifetime.Transient); services.AddTransient<MyViewModel, MyViewModel>(); And in the ViewModel: public class MyViewModel : INotifyPropertyChanged { public MyViewModel(MyContext referenceContext) { _myContext = myContext; } public async Task<IEnumerable<Dto>> GetList(string s) { return await _myContext.Table1

Is it possible to get a list of RenderFragments when overriding BuildRenderTree?

人走茶凉 提交于 2019-12-25 01:24:49
问题 I'm wondering if it's possible to reference child elements in the ChildContent parameter of a component. I can pass values from parent components to children explicitly or by using a cascading parameter, but there is no great way for a parent component to "know" about elements inside the ChildContent RenderFragment . A possible use-case for this would be a UIList component that gets the number of UIListItems that have been added to the UIList component during the render process. I've

Child Blazor app on Blazor Server side app

前提是你 提交于 2019-12-24 16:07:58
问题 Adding a Client side Blazor app to a Server Side Blazor app Hi Following on to the helpful answer here Blazor sub app 404 error after upgrade to Preview 6 I have run into a situation where it would be helpful to be able to add a Client side Blazor app to a Blazor server side app I have created the Blazor Server app, attached a client app the the server app, and adjusted the server startup.cs to map the child app. I have also confirmed the client apps index.html base value is correct app

Blazor: Access parameter from layout

时光毁灭记忆、已成空白 提交于 2019-12-24 15:28:54
问题 How can I access a page's route parameter from the layout? I have a page that accepts a route parameter like the following: @page /my-page/{Slug} I am needing to access the value of Slug when rendering markup in the shared layout. I have tried implementing OnParametersSet in the layout file like the following, but the value is not set. It's only assigned at the page level. @inherits LayoutComponentBase <div class="sidebar"> <NavMenu /> </div> <div class="main"> <div class="top-row px-4">

How to sign out over HttpContext in server-side Blazor

余生颓废 提交于 2019-12-24 11:18:22
问题 I access the HttpContext in a Blazor server-side view to manually log out. I added this line to Startup.cs: services.AddHttpContextAccessor(); and inject it in the view with @inject IHttpContextAccessor HttpContextAccessor . I've got a log out button which tries to execute this code: await HttpContextAccessor.HttpContext.SignOutAsync("Cookies"); but I get the following error message: System.InvalidOperationException: 'Headers are read-only, response has already started.' How can I prevent

Data binding in Blazor: How to propagate values out of a component?

笑着哭i 提交于 2019-12-24 08:18:24
问题 I have a fairly simple component, which looks like this: <form> <div class="form-group"> <label for="sampleText">Sample Text</label> <input type="text" class="form-control" id="sampleText" aria-describedby="sampleTextHelp" placeholder="Enter a text" @bind="@Value" /> <small id="sampleTextHelp" class="form-text text-muted">Enter a text to test the databinding</small> </div> </form> <p>You entered here: @Value</p> @code { [Parameter] public string Value { get; set; } } I now add this to a page

Blazor MatMenu taken last value in all menu in foreach loop

落爺英雄遲暮 提交于 2019-12-24 06:48:52
问题 MatMenu carrying last instance for all the listitems in foreach loop @foreach (var sub in subs) { <MatButton Label="Menu" OnClick="@OnClick" RefBack="@buttonForwardRef"></MatButton> <MatMenu @ref="Menu" TargetForwardRef="@buttonForwardRef"> <MatList SingleSelection="true"> <MatListItem>@sub.SubName</MatListItem> </MatList> </MatMenu> } Everey row want differene menu 回答1: Your issue is that you are sharing buttonForwardRef between all menus. Do you need new references for each menu: @using

How to use jQuery UI from Blazor component

与世无争的帅哥 提交于 2019-12-24 06:42:24
问题 I am working through some Blazor examples, and while trying to work with some JSInterop solutions, I ran into an issue with jQuery UI elements. I am not a proficient Javascript programmer, but I am proficient enough with .NET so I may be missing something simple. The first jQuery UI component I have tried to work with is the "resizable" component, found here: https://jqueryui.com/resizable/ Here is what my current code looks like: index.html: <!DOCTYPE html> <html> <head> <meta charset="utf-8

Blazor Component TwoWay Databinding

核能气质少年 提交于 2019-12-24 05:10:37
问题 I've made a Blazor component this way: <input bind-value-oninput="Title" /> @functions { [Parameter] string Title { get; set; } [Parameter] EventCallback<string> TitleChanged { get; set; } } Parent: @page "/fetchdata" Parent:<input bind-value-oninput="Title" /> - Child:<Comp bind-Title="Title"></Comp> @functions { string Title; } as expected editing the parent input propagate it's value to the component but not viceversa, is that by design right? I achieved two-way behaviour with this edit:

How does blazor detect authorized / notautorized

早过忘川 提交于 2019-12-24 00:57:59
问题 I am making a custom AuthenticationStateProvider to test in a Blazor app. I am worried that the new class won't have the same functionality as the AuthenticationStateProvider class because I'm not sure how AuthenticationStateProvider works. Below I posted my custom class. Could you please tell me if this is the accepted way of overrideing this class? public class ServerAuthenticationStateProvider : AuthenticationStateProvider { string UserId; string Password; bool IsAuthenticated = false;