0

I am migrating my web application from ASP.NET MVC to ASP.NET Core 2.0. But I having problem on setting html attributes in the Tag Helpers for Select Tag. For example, in my old project I have the below html helper for drop-down list.

var cssClass = "select-arrow " + Model.ControlCss;                        
@Html.DropDownListFor(model => model.Value, options, "", new { @class = cssClass })

Here, I have used the bellow html attributes for the html helper class to add another CSS classes.

new { @class = cssClass }

Now my question is how do I set the html attributes in asp.net core? Does the blow code work? Please let me know the details.

<select asp-for="Value" asp-items="options" class="form-control, cssClass"></select>

1 Answer 1

1

You can insert a string using @PropertyName:

<select asp-for="Value" asp-items="options" class="form-control select-arrow @Model.ControlCss" />
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer. Can you please suggest me the alternative for @Html.ValidationMessage("InputText") in Tag Helper.
I'm sure folks will here will be able to help but please post additional questions separately.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.