Reputation: 579
I have been trying to bind mudblazor datepicker to a DateTime property using Date.
<MudDatePicker Label="Start Date" Date="@StartDate" />
<MudTextField Label="SelectedDate" @bind-Value="@StartDate" />
<MudText Typo="Typo.h3">Selected Date is: @StartDate</MudText>
@code
{
public DateTime StartDate { get; set; }
public string DateString { get; set; }
}
I have tried this code on their site and in visual studio The code will update the Date Picker and my Text output when leaving the text field, this is normal behavior. However, I want to change the Text based on my selection of Date picker. I have tried binding to date and value. both don't reflect the selection I have made.
I have checked the documentation on their site and there is nothing on how to handle binding beyond what I am doing.
If any one knows how to bind Date picker in mudblazor please help. Thanks
Upvotes: 9
Views: 11757
Reputation: 114
I was having a similar issue with MudDateRangePicker. I found that I could use a nullable or a non-nullable DateRange variable but if I wanted to get the currently selected Start & End dates from a callback function, I would have to call the DateRangePicker.Close() method before I checked the dates. Just FYI if anyone else is looking at this issue.
Upvotes: 0
Reputation: 579
for anyone interested here is the answer: A Date picker in Mudblazor will only bind to a nullable DateTime, and I have to use @bind-Date. So my sample code that should work looks like this:
<MudDatePicker Label="Start Date" @bind-Date="@StartDate" />
<MudTextField Label="SelectedDate" @bind-Value="@StartDate" />
<MudText Typo="Typo.h3">Selected Date is: @StartDate</MudText>
@code
{
public DateTime? StartDate { get; set; }
}
Upvotes: 21