asp.net-blazor

Best way to share data between two child components in Blazor

泄露秘密 提交于 2020-07-09 12:07:17
问题 I have this code. <ParentComponent> <ChildComponet> @renderFragment </ChildComponent> <ChildComponetn> <GridComponent Data="@dataList"/> </ChildComponent> </ParentComponent> where @renderFragment is dynamically render componet and Grid componet is list of some data with actions like "add new", "edit record", "delete". If we click "add new", form for add new record is opened dynamically in @renderFragment and we want to refresh grid data after submit form but we don't know how to share some

How can I host ASP.NET API and Blazor Web Assembly like an JavaScript-SPA?

余生长醉 提交于 2020-06-11 07:55:08
问题 Context: We want to create a Single Page Application that runs with Blazor WebAssembly on the client-side. On the server-side, the solution has an ASP.NET MVC which includes some ApiController classes for our REST APIs. We want to use ASP.NET API on the server-side instead of Blazor Server because we want to provide a REST interface with ApiController classes for unknown consumers. Here is my client-side (Blazor WebAssembly) and server-side (ASP.NET API) project in a single solution: A first

How to trigger Blazor's EditForm submit from a button that is outside of it?

非 Y 不嫁゛ 提交于 2020-03-25 17:56:30
问题 I want to make a component that have a EditForm and encapsulate the form and the validation inside of the component. And I want to reuse this component anywhere in my application and submit it using any button. How can I submit a EditForm from a button that is outside of it? Observation : I have searched for other answers like this one but the answer that is marked as accepted doesn't answer the question and that is why I'm making this new question. 回答1: Instead of including the EditForm in

Change class for selected div only

好久不见. 提交于 2020-03-05 04:36:57
问题 I would like it to only change the class for the clicked div . Currently it will change the class for all div s. I have written this as a Blazor component. @for (int i = 0; i < 5; i++) { <div class="@divClass" @onclick="_ => ChangeDivClass()">@i</div> } @code { String divClass; private void ChangeDivClass() { if (divClass == "red") { divClass = String.Empty; } else { divClass = "red"; } } } 回答1: You can use an array instead of one variable. @for (int i = 0; i < divClass.Length; i++) { var