blazor

Blazor UriHelper.NavigateTo is calling the page twice

会有一股神秘感。 提交于 2019-12-11 17:59:18
问题 I created a new Blazor Server Side Application in Preview 8. When I call the UriHelper.NavigateTo to go to the counter page from the Index.razor page, the counter page is called twice. In the Index.razor page I have this code: @code{ protected async override Task OnInitializedAsync() { UriHelper.NavigateTo("/counter"); } } Then in the counter page I added the following code with a breakpoint in it: protected override void OnInitialized() { } My expectation is to call the counter page only one

Is there a way to update a binding variable attached to an Input text Item in Blazor when using Ctrl +V combination keys?

扶醉桌前 提交于 2019-12-11 17:05:15
问题 I have this input which is to capture a phone number. When the user enters a number and press the "Enter" Key the Method "KeyWasPressed" is triggered and some validation happens. this works as expected BUT... When the user copies and pastes the number from excel, for example, the variable @Phone doesn't updates its value so when the user presses the "Enter" key the validation sends and empty value. Is there a way to refresh/update @Phone variable when some text is pasted to the input control?

Getting ArgumentOutOfRangeException using for loop in Blazor component

依然范特西╮ 提交于 2019-12-11 16:58:36
问题 I'm trying out Blazor and I'm getting this exception when I'm trying to load a list of checkboxes using a for loop. I've created the list here: public List<Month> Months { get; set; } protected override void OnInitialized() { List<Month> months = new List<Month>() { new Month{MonthId = 0, MonthName = "All Months", isMonthChecked = false}, new Month{MonthId = 1, MonthName = "Jan", isMonthChecked = false}, new Month{MonthId = 2, MonthName = "Feb", isMonthChecked = false}, new Month{MonthId = 3,

Updating other Blazor components from elsewhere in the application

你。 提交于 2019-12-11 15:52:04
问题 Consider a scenario where you have a dynamic navigation (a list of cheese categories, let's say). The navigation component exists on the layout, which has various other content components. One of those allows the user to update the name of the selected cheese category. But...how do we reflect that back on the navigation component? If one viewed it as a tree you'd have to navigate (in code) up to the layout, then navigate down to the the navigation component where the state can be updated

Blazor: Redirect to Login page when there is no session / JWT token?

馋奶兔 提交于 2019-12-11 11:34:26
问题 I am trying to create a new application in Blazor and am working on authentication. I am using a JWT tokens that is stored in Local storage. When the application loads i need to check if there is a token in the storage. If so, add it to the HTTP headers for all API requests, if not then redirect to the login page before the page loads....... where do i do that? There are multiple pages that need this check so this needs to be done in a single location to cover all. Should this be done in the

Share Data Through Service in ASP.NET Blazor (Client Side)

南笙酒味 提交于 2019-12-11 11:01:54
问题 I use to have a common service in MVC Application , register it as Transient service and access its value across whole application without any issue . I tried to implement same mechanism inside my client side blazor app First created a class AppState public class AppState { public string BaseUrl { get; set; } } registered as a service services.AddSingleton<AppState, AppState>(); Used in Blazor Component Index Component public class IndexComponent : ComponentBase { [Inject] HttpClient Http {

add list of dynamic components in blazor

狂风中的少年 提交于 2019-12-11 08:39:24
问题 I just started to have a look in blazor (v0.3) and doing some test I wanted to add a list using blazor First I created a List<string> to test a simple list in the same page <ul> @foreach (var item in listItems) { <li>@item</li> } </ul> @functions { private List<string> listItems = new List<string>(); private string newItem; private void AddItem() { if (string.IsNullOrEmpty(newItem)) return; listItems.Add(newItem); newItem = ""; } } this is working fine, is adding every element to the list

Blazor Change Validation default css class names

試著忘記壹切 提交于 2019-12-11 08:14:12
问题 I'm Trying Microsoft Blazor and when working with forms and validation I stopped on how can I change the default CSS class that will be added by default on InputText Validation State. For Explanation when InputText has an error by default take class "invalid" I want to change this class to "is-invalid" I Need best practises Thanks, StackOverflow community 回答1: Any HTML element (or InputText) attribute including the class, can be 'one-way' bound to a variable or expression. So in your case,

Blazor sub app 404 error after upgrade to Preview 6

纵饮孤独 提交于 2019-12-11 07:49:16
问题 In Blazor Preview 5 (.Net Core Hosted), I have successfully configured the app as a sub app on the Asp.net Core site using: app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapDefaultControllerRoute(); endpoints.MapRazorPages(); }); app.UseMvcWithDefaultRoute(); app.Map("/superadmin", child => { child.UseBlazor<BlazorCoreHosted.SuperAdmin.Startup>(); }); I am now trying to upgrade to Preview 6, but when the app loads I get a 404 error "Failed to load resource: the server responded

How do I add a Bearer Token to the header of a HTTP request?

≯℡__Kan透↙ 提交于 2019-12-11 07:47:51
问题 I am having trouble figuring out how to set authorization headers with authorization as the key and a bearer token as the value. I have completed a web API with authentication built into it. i have tested it on postman and it all works. the problem is on post man i take the token copy past it to a new key and value, in the site i am not sure how to change those values in a Blazor project. When entering a Get to the API at http://testapi.com/api/token/{username}/{password} the API sends back a