3

Is it possible to add an attribute to an input field without the value whilst using @Html.TextBoxFor() - notice how the "data-plugin-datepicker" name has no value in the code snippet below.

So what I want is this:

<input name="DoB" id="DoB" type="text" data-plugin-datepicker class="form-control">

By using this:

@Html.TextBoxFor(m => m.DoB, new { @class = "form-control", ??? })
Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
Bern
  • 7,808
  • 5
  • 37
  • 47
  • this will help you get part of the way there: http://stackoverflow.com/a/4515095/526704 – DLeh Apr 09 '15 at 16:08
  • check the this answers http://stackoverflow.com/q/16023943/2907017 – Sherif Ahmed Apr 09 '15 at 16:09
  • 2
    Adding an "empty" attribute, so far as I can tell, is not possible in MVC5 with the built-in helpers except for a few cases where MVC knows to handle it specially (like disabled). It use to be possible by assigning to to an empty string, but at some point that changed. – vcsjones Apr 09 '15 at 16:18
  • Thanks @vcsjones - you're right, still it works with an empty string attribute value so I'll resort to that. – Bern Apr 10 '15 at 09:30
  • It appears to be working using an empty string in the latest (MVC 5.2.7). Possibly was broken for a while then fixed again? – Josh Mc Nov 21 '19 at 21:45

0 Answers0