1
new { id = " dd" name = " myName" } 

is not on the name attributes override, how can id coding name attributes override

@Html.DropDownListFor(x => x.Customer.CustomerBiaoshi, Html.GetEnumSelectList<TgNetJZ.CustomerBiaoshi>(), "test",new { @class = "form-control custom-select" ,@id="ddd",@name="myName"})

I write like this always shows model name Customer.CustomerBiaoshi, I want to show what I set name attributes "myName"

enter image description here

It should be for me that the edit page can only use dropdownlistfor to bind the drop-down box to select items, so I need to solve the name property Customer.CustomerBiaoshi override and Model corresponds to CustomerBiaoshi

or how to custom dropdownlist htmlstring on mvc core suppet set name attributes like so

1 Answers1

0

You can use another version of dropdownlist creator as

@Html.DropDownList(string "name", IEnumerable<SelectListItem> selectList, 
                   object htmlAttributes) 

In your case:

@Html.DropDownList("myName", Html.GetEnumSelectList<TgNetJZ.CustomerBiaoshi>(),
                    new { @class = "form-control custom-select", @id = "ddd" }).

But your model binding to Customer.CustomerBiaoshi will not work, because model binding uses name attribute and you changed the name attribute to myName.

Farid Imranov
  • 2,017
  • 1
  • 19
  • 31
  • my edit form use dropdownlistfor to bind selection but my Dto Field CustomerBiaoshiI need to set the name and dto correspondence to assignSo I can only solve the name attributes override with dropdownlistfor –  Mar 05 '20 at 11:06
  • 1
    This cannot be marked as answer when it doesn't solve the problem. `DropDownList` is different from `DropDownListFor` in world of model binding. – Zeeshan Jul 26 '22 at 14:11