Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DropdownList without a name attribute

I'm building a form in my project, but because I'm using AJAX to post the form values and multiple instances of a certain dropdown (class attribute instead of id), I'm not in need of a name attribute on my form controls.

Is there a way to create a dropdown list dynamically but explicitly omitting the name attribute without getting an exception?

@Html.DropDownList(string.Empty, Model, new { @class = "year" })

Gives me this exception:

Value cannot be null or empty. Parameter name: name

because first argument is empty.

like image 361
silkfire Avatar asked Feb 11 '26 05:02

silkfire


1 Answers

You can do it like following.

@Html.DropDownList("aName", Model, new { Name=string.Empty, @class = "year" })
like image 62
Ibrahim Khan Avatar answered Feb 15 '26 04:02

Ibrahim Khan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!