ASP.NET MVC 3 Razor - Adding class to EditorFor

后端 未结 16 2055
长情又很酷
长情又很酷 2020-11-27 11:09

I\'m trying to add a class to an input.

This is not working:

@Html.EditorFor(x => x.Created, new { @class = \"date\" })
16条回答
  •  春和景丽
    2020-11-27 11:53

    I just needed to set the size of one textbox on one page. Coding attributes on the model and creating custom editor templates were overkill, so I just wrapped the @Html.EditorFor call with a span tag that called a class which specifies the size of the textbox.

    CSS class declaration:

    .SpaceAvailableSearch input
    {
        width:25px;
    }
    

    View code:

    @Html.EditorFor(model => model.SearchForm.SpaceAvailable)
    

提交回复
热议问题