Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor EditForm: Query parameters not binding to DateTime inputs on navigation

$
0
0

I can't get the check-in and check-out dates I entered on the form. When I enter the values and submit, I see the default values I assigned at the beginning(Datetime.Now and the next day), and I don't know how to solve the problem.

@inject NavigationManager Navigation<EditForm Model="@searchModel" OnValidSubmit="Submit" FormName="BookingForm" class="book_now"><ValidationSummary /><div class="row"><div class="col-md-12"><span>Arrival</span><img class="date_cua" src="/template/images/date.png"><InputDate class="online_book" @bind-Value="searchModel.CheckIn" /><div class="mb-3">Entered date: @searchModel.CheckIn</div></div><div class="col-md-12"><span>Departure</span><img class="date_cua" src="/template/images/date.png"><InputDate class="online_book" @bind-Value="searchModel.CheckOut" /><div class="mb-3">Entered date: @searchModel.CheckOut</div></div><div class="col-md-12"><button type="submit" class="book_btn">Book Now</button></div></div></EditForm>@code {    private BookingSearchModel searchModel = new();    private void Submit()    {        var url = $"/available-rooms?checkIn={searchModel.CheckIn:yyyy-MM-dd}&checkOut={searchModel.CheckOut:yyyy-MM-dd}";        Navigation.NavigateTo(url);    }    public class BookingSearchModel    {        [Required]        [DataType(DataType.Date)]        public DateTime CheckIn { get; set; } = DateTime.Now;        [Required]        [DataType(DataType.Date)]        public DateTime CheckOut { get; set; } = DateTime.Today.AddDays(1);    }}

The only thing I'm waiting for is to take the data I entered in the form and create my URL correctly.

for example must be https://localhost:7082/available-rooms?checkIn=2025-08-28&checkOut=2026-11-29but I just have default valueshttps://localhost:7082/available-rooms?checkIn=2025-08-28&checkOut=2025-08-29


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>