MVC3 HTMLHelper defaults

前端 未结 2 1396
-上瘾入骨i
-上瘾入骨i 2021-01-22 03:44

I have an html helper that I\'d like to set a default on.

@Html.EditorFor(model => model.DateFrom)

What\'s the syntax to set the default val

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-22 04:07

    I believe the only HTML Helper that supports a default value is the Html.DropDownList(). It has an optionLabel parameter that allows you to set the default option at the top of the dropdown list. For example:

    Html.DropDownList("CustomerId", "Select a Customer")
    

    As Henry, mentioned if you would like to set a default value on other HTML helpers, set it within the model or roll your own helper.

提交回复
热议问题