Is it possible to change the HTML output of the DropDownList?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
I have fully managed to customize 95% of the Register.cshtml page and it is working great with the default value's and custom fields. However, i do have a problem i am not able to customize the following:

@Html.DropDownList("CountryId", Model.AvailableCountries)

I want to customize the HTML order div's, classes and elements inside this dropdown.

Is it possible to do this by any change the easy way like copying the .cshtml files into your theme directory
and overwriting the files.

Would be great if i could do this.

Appreciate the help as always.

Thanks in advance.

Warm regards,
Nino
6 years ago
Hello Nino,

You should render drop-down by hand, create your custom HTML helper or try JS library like https://select2.github.io/ and customize you layout in JavaScript. Personally, I'd prefer the option with custom HTML helper.
6 years ago
ilich_x86 wrote:
Hello Nino,

You should render drop-down by hand, create your custom HTML helper or try JS library like https://select2.github.io/ and customize you layout in JavaScript. Personally, I'd prefer the option with custom HTML helper.


How would i use a custom HTML helper? I have created a custom HTML/CSS/JS Dropdown with UL and LI items. However i made it work on the simple product page because i was able to customize the <select> Menu directly.

What do i have to do and how can i do it?

Thanks in advance.

Warm regards,
Nino
6 years ago
You can start with https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/views/creating-custom-html-helpers-cs article. HTML helpers will require some C#/.NET programming. Make sure you DLL with the helper is copied to <wwwroot>/bin folder.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.