這可能很簡單,但我找不到任何內容。我的代碼有效,但我不知道如何設定默認日期:
<div class="col-md-12 text-center">
@using (Html.BeginForm())
{
<label asp-for="StartDate"></label><br />
@Html.EditorFor(model => model.StartDate, new { htmlattributes = new { @class = "datepicker" } })
<br />
<label asp-for="EndDate"></label><br />
@Html.EditorFor(model => model.EndDate, new { htmlattributes = new { @class = "datepicker" } })
}
</div>
任何人都可以指出我正確的方向嗎?謝謝!
uj5u.com熱心網友回復:
你可以嘗試設定的默認值Model.StartDate和Model.EndDate。這里是一個演示:
模型:
public class TestModel
{
public DateTime StartDate { get; set; } = new DateTime(2021, 10, 14, 8, 30, 52);
public DateTime EndDate { get; set; }= new DateTime(2021, 10, 15, 8, 30, 52);
}
行動:
public IActionResult Index1()
{
return View();
}
結果:

或者您可以嘗試設定Model.StartDate并執行以下Model.EndDate操作:
模型:
public class TestModel
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}
行動:
public IActionResult Index1()
{
return View(new RandomModel { StartDate = new DateTime(2021, 10, 15, 8, 30, 52),EndDate = new DateTime(2021, 10, 16, 8, 30, 52)});
}
結果:

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/317614.html
