Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding a value in Blazor with a specific format

Tags:

blazor

Is is possible to bind a value in Blazor client in particular format.

For example

<input type="text" bind="@TestDate.ToString("dd.MM.yyyy")" />

@code
{
protected DateTime TestDate {get;set;} = DateTime.Now;
}

I tried to do

<input type="text" bind="@TestDate" format-value="dd.MM.yyyy" />

but that didnt do anything, i received a value such as 11/12/2019 1:03:17 PM

like image 911
mko Avatar asked Nov 12 '19 13:11

mko


People also ask

How do you bind input value in Blazor?

Bind a property or field on other Document Object Model (DOM) events by including an @bind:event="{EVENT}" attribute with a DOM event for the {EVENT} placeholder. The following example binds the InputValue property to the <input> element's value when the element's oninput event ( input ) is triggered.

How do you bind a label to value in Blazor?

You can use the bind attribute on any element to bind the value. In blazor, we'll have a property assigned some value in the functions and use the property in the HTML template. Let's get this done. So, when we run the app, the label tag will display “red” as a text in the label.

What is the difference between bind and bind value in Blazor?

In Blazor, there is no significant difference between using these two attributes. The @bind attribute is a shorthand of the @bind-value attribute and its delegate will trigger the ValueChanged event of the component.

How do you bind a dropdown value in Blazor?

We can bind a drop-down list in Blazor WebAssembly using the <select> tag and bind the values to the drop-down list using the @bind attribute in the tag.


1 Answers

It's bind:format, you have sample in the doc : Data binding paraph format string

<input @bind="StartDate" @bind:format="yyyy-MM-dd" />

@code {
    [Parameter]
    public DateTime StartDate { get; set; } = new DateTime(2020, 1, 1);
}
like image 107
agua from mars Avatar answered Oct 22 '22 02:10

agua from mars