blazor

Blazor - razor page not updating after property from DI Service is changed

隐身守侯 提交于 2020-01-30 07:49:06
问题 Using dotnet 3.1.100-preview2-014569 Ok consider the following example: Create a new Blazor WebAssemply project from template, then add the following: books.razor @page "/books" @inject BookService bookService @if (bookService.isLoaned) { <p><em>Book loaned</em></p> } else { <p><em>Book returned</em></p> } BookService.cs public class BookService { public int BookId { get; set; } public string Title { get; set; } public bool isLoaned { get; set; } } Startup.cs public void ConfigureServices

Developing Blazor Razor component in VS with dual screens

只愿长相守 提交于 2020-01-29 23:31:30
问题 Is there a way to open Razor component in Visual Studio with environment with dual screens . I'll love to have markup on one screen and @code {} section on other. While MVC developing usually markup is on one screen while JS is on other. Switching to Blazor C# replaces JS,But my mind is still mapped to read markup from one while is code on other. Can we create component with code separated from markp but still connected. 回答1: You can use the code behind with a partial class : MyComponent

Merge scaffolded Login page into Razor page

强颜欢笑 提交于 2020-01-26 03:54:08
问题 I work with Blazor and dotnet core 3.1.1 created a sample Server Side application and scaffolded a login and register page (Identity Scaffold). Problem is now that I want to merge the functionality of the cshtml files into the given razor files. Exactly: I want to take the functionality of Step 1 (see screenshot) into the Counter.razor file (Step 2). problem is that the cshtml takes properties, classes and files into account that are not known in my razor file. e.g.: public async Task

Blazor GetAsync request returns 401 status code

ⅰ亾dé卋堺 提交于 2020-01-25 10:21:09
问题 I am new to blazor and trying to create an application using .NET Core /EF Core 3 and Visual studio 2019. I have setup a database model and an API for getting all addresses (/api/Address) and browsing to this in a browser returns all of the records in the database. But my My GetAsync method in the Razor file returns 401 which finally returns null. Here is my Razor code: @functions { Address[] addresses; protected override async Task OnInitializedAsync() { addresses = await Http.GetJsonAsync

How do I create a cookie client side using blazor

喜你入骨 提交于 2020-01-25 07:26:27
问题 I have a login page that goes off to the server gets a bunch of data, then I want to take some of that data and save it into a cookie using Blazor on the client. So To start I have successfully injected IHttpContextAccessor. and for now in my Blazor function I have: httpContextAccessor.HttpContext.Response.Cookies.Append("test", "ddd"); in debug when I hit the above line of code it errors with: "Headers are read-only, response has already started." Of course I will not be saving "test" with

Browser Link not refreshing page in Chrome

狂风中的少年 提交于 2020-01-25 06:52:27
问题 I am following this documentation to enable Browser Link and set up a new Blazor project (targeting .NET Core 3 ) using the provided template (running Visual Studio 16.3.9, which is latest as of writing). As mentioned in the documentation I have installed the nuget package Microsoft.VisualStudio.Web.BrowserLink and added the middleware to my Startup.cs public class Startup // ... public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app

Blazor: Call a server method when a button is clicked?

我与影子孤独终老i 提交于 2020-01-24 21:01:06
问题 I created a sample Blazor project. The scaffolding has two examples, (1)calling a C# method that exists IN the web page = counter, (2)calling a server method at the BEGINNING of the web page initialisation = weather table. But not any example for calling a server method and get result when a button is clicked. Is that possible? For example, can I add a method like this to the "WeathrForecastService.cs": public int Add(int a, int b) { return a + b; } and like the "counter" example, add a

How to automatically execute a js event (non-click event) when dotNetCore Blazor loads an index.razor page

半世苍凉 提交于 2020-01-24 20:38:09
问题 Excuse me, everyone, how to enter Index.razor to automatically execute a js event The carousel plugin used needs to automatically execute the following code function(){ $("#banner").owlCarousel({ autoPlay : 3000, paginationSpeed : 1000, goToFirstSpeed : 2000, singleItem : true, autoHeight : true, navigation: true, transitionStyle: 'fade' }); } Such ineffective no longer should need to load the event in the child page _Host.cshtml 出现一个错误 Index.razor 出现Object reference not set to an instance of

Blazor Grid Bound Column by Field Name

核能气质少年 提交于 2020-01-24 18:23:06
问题 I'm studying some paid grid components and they have a pretty cool "Bound Column" technique: <TelerikGrid Data=@GridData> <GridColumns> <GridColumn Field="TemperatureC" Title="Temp. C" /> <GridColumn Field="Summary" /> </GridColumns> <GridToolBar> <GridCommandButton Command="Add" Icon="add">Add Forecast</GridCommandButton> </GridToolBar> </TelerikGrid> <DxDataGrid Data="@DataSource"> <DxDataGridColumn Field="@nameof(ProductFlat.Id)"> </DxDataGridColumn> <DxDataGridColumn Field="@nameof

Blazor: How to use the onchange event in <select> when using @bind also?

浪子不回头ぞ 提交于 2020-01-24 05:24:26
问题 I need to be able to run a function after a selection in made in a <select> . The issue is I'm also binding with @bind and I get a error when I try to use @onchange stating that it is already in use by the @bind. I tried using @onselectionchange, but that does nothing(doesn't run the function). I could forget the @bind and just assign @onchange to a function, but I'm not sure how to pass the selected value to the function. I have the following code: <select @bind="@SelectedCustID" @ @onchange