I have a custom InputDate control in blazor that works fine but when I run my pp I get 01/01/0001 instead of dd/mm/yyyy.
I want to set dd/mm/yyyy if I don't set the time to NOW
if I use InputDate as normal it works fine and shows me dd/mm/yyyy but in the custom control I get some errors
here is my model:
public class Quote
{
[Required(ErrorMessage = "Quote Date is a required field.")]
public DateTime? QuoteDate { get; set; }
}
and the Customs Control:
@using System.Linq.Expressions
@inherits InputBase<DateTime>
<div class=@ColumnLocation>
@if (!string.IsNullOrWhiteSpace(Label))
{
<label for="@Id">@Label</label>
}
<InputDate @bind-Value="@CurrentValue" class="form-control" placeholder="Enter date of preference"></InputDate>
<ValidationMessage For="@ValidationFor" />
</div>
@code {
[Parameter] public string Id { get; set; }
[Parameter] public string Label { get; set; }
[Parameter] public Expression<Func<DateTime>> ValidationFor { get; set; }
protected override bool TryParseValueFromString(string value, out DateTime result, out string validationErrorMessage)
{
result = DateTime.Parse(value);
validationErrorMessage = null;
return true;
}
}
and the page:
@page "/counter"
<EditForm Model="quote" OnValidSubmit="@SubmitButtonPressed" class="form-horizontal">
<DataAnnotationsValidator />
@*for this custom control I've had some errors*@
<UxInputDate Label="Quote Date3" @bind-Value="quote.QuoteDate"
ValidationFor="@(() => quote.QuoteDate)"/>
@*for this normal control everything is fine*@
<InputDate @bind-Value="quote.QuoteDate" class="form-control" ></InputDate>
<button type="submit" class="btn">Check 1</button>
</EditForm>
@code {
Quote quote = new Quote();
protected void SubmitButtonPressed()
{
....
}
}
errors:
cannot convert from 'Microsoft.AspNetCore.Components.EventCallback<System.DateTime?>' to 'Microsoft.AspNetCore.Components.EventCallback'
Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
Cannot implicitly convert type 'System.DateTime?' to 'System.DateTime'. An explicit conversion exists (are you missing a cast?)