blazor

How to add controller (not view) support to a server-side Blazor project

主宰稳场 提交于 2021-02-07 02:36:07
问题 While my server-side Blazor app is running, I want some Javascript code in _Host.cshtml to be able to post data to a controller action. Of course, this happens completely outside of the scope of, and is unrelated to, the Blazor app itself. I thought this would be a matter of adding calls to services.AddControllers() and endpoints.MapControllers() at the appropriate places in Startup.cs . However, after doing this, and implementing the controller action, I made the following observations:

Loading an external .NET Standard 2.0 assembly with blazor

左心房为你撑大大i 提交于 2021-02-06 11:29:15
问题 In a Blazor app, I want to load an external assembly and execute a method. For this, I have created a new ASP.Net Core webapplication using the Blazor template. Then, in a Razor Page (which will be compiled and executed by browser/wasm) I use reflection to load the assembly and run the method (based on code found here) // download external assembly from server HttpClient client = new HttpClient(); var bytes = await client.GetByteArrayAsync("http://localhost:62633/_framework/MyCustomLib.dll");

Loading an external .NET Standard 2.0 assembly with blazor

依然范特西╮ 提交于 2021-02-06 11:22:07
问题 In a Blazor app, I want to load an external assembly and execute a method. For this, I have created a new ASP.Net Core webapplication using the Blazor template. Then, in a Razor Page (which will be compiled and executed by browser/wasm) I use reflection to load the assembly and run the method (based on code found here) // download external assembly from server HttpClient client = new HttpClient(); var bytes = await client.GetByteArrayAsync("http://localhost:62633/_framework/MyCustomLib.dll");

Loading an external .NET Standard 2.0 assembly with blazor

荒凉一梦 提交于 2021-02-06 11:21:05
问题 In a Blazor app, I want to load an external assembly and execute a method. For this, I have created a new ASP.Net Core webapplication using the Blazor template. Then, in a Razor Page (which will be compiled and executed by browser/wasm) I use reflection to load the assembly and run the method (based on code found here) // download external assembly from server HttpClient client = new HttpClient(); var bytes = await client.GetByteArrayAsync("http://localhost:62633/_framework/MyCustomLib.dll");

How to Localize validation message (DataAnnotationsValidator) in blazor server side

北战南征 提交于 2021-02-06 10:13:10
问题 I am using blazor 3.1 in latest version of VS 2019. So far, I am able to localize page labels (title, table fields etc.). On the ListEmployee.razor page, I am able to localize table heading etc. On the AddEmplyeeValidation.razor page, I am able to localize form labels but I have a problem localizing the validation messages. For validation message for the Employee.cs file, validation message are defined in the Resources/Data folder in files Data.Employee.resx and Data.Employee.ar.resx but this

How to Localize validation message (DataAnnotationsValidator) in blazor server side

依然范特西╮ 提交于 2021-02-06 10:12:21
问题 I am using blazor 3.1 in latest version of VS 2019. So far, I am able to localize page labels (title, table fields etc.). On the ListEmployee.razor page, I am able to localize table heading etc. On the AddEmplyeeValidation.razor page, I am able to localize form labels but I have a problem localizing the validation messages. For validation message for the Employee.cs file, validation message are defined in the Resources/Data folder in files Data.Employee.resx and Data.Employee.ar.resx but this

Blazor's WebApi returns text/html instead of application/json

南楼画角 提交于 2021-02-05 07:21:26
问题 My controller's methods in Blazor's server side WebApi returns an html/text response instead of application/json which leds to The provided ContentType is not supported; the supported types are 'application/json' and the structured syntax suffix 'application/+json'. error. What is the best way to manually set the content type of the response to application/json? My Controller with a Get method [Route("api/[controller]")] [ApiController] public class DeveloperController : ControllerBase {

Can I add to or change the default CSS class when using ValidationMessage in ASP.NET Core?

心已入冬 提交于 2021-02-05 02:58:09
问题 I am using ValidationMessage in a razor component to show validation message, like this: <ValidationMessage For="@(() => ViewModel.CompanyNumber)" /> This generates this HTML code: <div class="validation-message">The company number field is required.</div> Is it possible to change the CSS-class? I want to use something else than validation-message . Adding class="myclass" is ignored by the controller. I've also tried with @attributes without success. 回答1: With .NET5 they added functionality

Can I add to or change the default CSS class when using ValidationMessage in ASP.NET Core?

空扰寡人 提交于 2021-02-05 02:54:52
问题 I am using ValidationMessage in a razor component to show validation message, like this: <ValidationMessage For="@(() => ViewModel.CompanyNumber)" /> This generates this HTML code: <div class="validation-message">The company number field is required.</div> Is it possible to change the CSS-class? I want to use something else than validation-message . Adding class="myclass" is ignored by the controller. I've also tried with @attributes without success. 回答1: With .NET5 they added functionality

Blazor page elements other than Body

此生再无相见时 提交于 2021-02-04 06:28:46
问题 I have a Blazor server-side app, trying to understand the structure. Inside the MainLayout.razor page, I see the tag @Body, and this is where each page's content is rendered. I am wondering, is it possible to add additional render element to the mainLayout page? For example, a @Header section. And I would prefer to define this section inside each individual page as well. In other words, for each page, besides the main content, it also needs to define Header, Footer, or whatever render element