Html.EditorFor Set Default Value

后端 未结 12 1839
夕颜
夕颜 2020-12-13 03:44

Rookie question. I have a parameter being passed to a create view. I need to set a field name with a default value. @Html.EditorFor(model => model.Id) I need to set this in

12条回答
  •  有刺的猬
    2020-12-13 04:04

    For me I need to set current date and time as default value this solved my issue in View add this code :

    @Html.LabelFor(model => model.order_date, htmlAttributes: new { @class = "control-label col-md-2" })
    @Html.EditorFor(model => model.order_date, new { htmlAttributes = new { @class = "form-control",@Value= DateTime.Now } }) @Html.ValidationMessageFor(model => model.order_date, "", new { @class = "text-danger" })

提交回复
热议问题