blazor form edit is not sending data to backend
@page "/register"
@using System.ComponentModel.DataAnnotations
@inject HttpClient http
<PageTitle>Registration</PageTitle>
<h1>Fill For Registration</h1>
<EditForm Model="@registration" OnSubmit="@Submit" FormName="RegisterForm" action="http://localhost:5234/User">
<div>
<label>Name:
<InputText @bind-Value="@registration.Name" />
</label>
</div>
<div>
<label>Surname:
<InputText @bind-Value="@registration.Surname" />
</label>
</div>
<div>
<label>Username:
<InputText @bind-Value="@registration.Username" />
</label>
</div>
<div>
<label>Email:
<InputText @bind-Value="@registration.Email" />
</label>
</div>
<div>
<label>Phone:
<InputText @bind-Value="@registration.Phone" />
</label>
</div>
<div>
<label>Age:
<InputNumber @bind-Value="@registration.Age" />
</label>
</div>
<div>
<button type="submit">Register</button>
</div>
</EditForm>
@code{
public class UserDto
{
public string Name { get; set; }
public string Surname { get; set; }
public string Username { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public decimal Age { get; set; }
}
private UserDto registration = new UserDto();
private async Task Submit()
{
var url = "http://localhost:5234/User";
await http.PostAsJsonAsync(url, registration);
}
}
@page "/register"
@using System.ComponentModel.DataAnnotations
@inject HttpClient http
<PageTitle>Registration</PageTitle>
<h1>Fill For Registration</h1>
<EditForm Model="@registration" OnSubmit="@Submit" FormName="RegisterForm" action="http://localhost:5234/User">
<div>
<label>Name:
<InputText @bind-Value="@registration.Name" />
</label>
</div>
<div>
<label>Surname:
<InputText @bind-Value="@registration.Surname" />
</label>
</div>
<div>
<label>Username:
<InputText @bind-Value="@registration.Username" />
</label>
</div>
<div>
<label>Email:
<InputText @bind-Value="@registration.Email" />
</label>
</div>
<div>
<label>Phone:
<InputText @bind-Value="@registration.Phone" />
</label>
</div>
<div>
<label>Age:
<InputNumber @bind-Value="@registration.Age" />
</label>
</div>
<div>
<button type="submit">Register</button>
</div>
</EditForm>
@code{
public class UserDto
{
public string Name { get; set; }
public string Surname { get; set; }
public string Username { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public decimal Age { get; set; }
}
private UserDto registration = new UserDto();
private async Task Submit()
{
var url = "http://localhost:5234/User";
await http.PostAsJsonAsync(url, registration);
}
}
1 Reply
and also my backend is working well. I tested with postman and also swing.