Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
241 views
in Technique[技术] by (71.8m points)

c# - How to assign class attribute to InputDate in blazor?

I want to assign a class attribute to <InputDate /> component. I tried using AdditionalAttributes but its syntax is not clear to me. What I ended up with is this:

<InputDate @bind-Value="Model.Task.TaskDate" @attributes="datePickerAttributes" />

@code {
    private Dictionary<string,object> datePickerAttributes = new Dictionary<string, object>()
    {
        ["class"] = "form-control"
    };
}

It works but looks messy. Is there a more concise way to achieve the same result?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You seem to be overthinking things, you want to assign a class - just do that.

<InputDate @bind-Value="Model.Task.TaskDate" class="form-control" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...