I'm trying to auto focus on a different area of a form depending on a field in the model. The following always renders the autofocus.
@Html.EditorFor(model => model.ManufacturerProduct.Specifications, new { htmlAttributes = new { @class = "form-control", autofocus = (Model.FocusOn == "Specifications" ? "" : null) } })
What I managed to do to get it to work was this, but it feels clunky.
@{
dynamic expando = new ExpandoObject();
expando.@class = "form-control";
if (Model.FocusOn == "Specifications") expando.autofocus = "autofocus";
}
@Html.EditorFor(model => model.ManufacturerProduct.Specifications, new { htmlAttributes = expando })
Is there a better way?