This is what I tried:
@Html.TextBoxFor(model => model.EntryDate, new { style="width:90px;",((_new || _modify) ? @disabled="disabled":"") }) @Html.ValidationMessageFor(model => model.EntryDate)
This is what I tried:
@Html.TextBoxFor(model => model.EntryDate, new { style="width:90px;",((_new || _modify) ? @disabled="disabled":"") }) @Html.ValidationMessageFor(model => model.EntryDate)
The following will work because there is only one html attribute
@Html.TextBoxFor(m => m.EntryDate, (_new || _modify)
? new { @disabled = "disabled" }
: null)
However once you add the style attribute, this will generate an error because there is no implicit conversion between new { @disabled = "disabled", @Style="width:90px;" } and new { @Style="width:90px;" } so you need to do this in an if block
@if(_new || _modify) {
@Html.TextBoxFor(m => m.EntryDate, new { @disabled = "disabled", style="width:90px;")}
} else {
@Html.TextBoxFor(m => m.EntryDate, new { style="width:90px;" })
}
Edit
Casting the html dictionary to object seems to work but I've not fully tested this (and I'm not sure that its "a simple and elegant way to to it")
@Html.TextBoxFor(m => m.EntryDate, (_new || _modify)
? (object)new { @disabled = "disabled", style="width:90px;" }
: (object)new { style="width:90px;" })
I am not sure but try this one:
@Html.TextBoxFor(model => model.EntryDate, (_new || _modify) ? new{ @Style="width:90px;", @Disabled="disabled"} : new{ @Style="width:90px;"})