I have the following model.
public class Customer
{
[Key]
public int CustomerId { get; set; }
public string CustomerName { get; set; }
public DateTime RegisteredDate { get; set; }
}
From the model, I generate scaffold controller. Then I have the following code:
public async Task<IActionResult> Edit(int? id)
{
if (id == null)
{
return NotFound();
}
var obj = await _db.Customers.FindAsync(id);
if (obj == null)
{
return NotFound();
}
return View(obj);
}
It will triggered when user clicked the edit
link on the table. But, the RegisteredDate
didn't retrieved to the view. I have the following view:
<input asp-for="CustomerId" hidden />
<input asp-for="CustomerName" />
<input asp-for="RegisteredDate" />
Why the RegisteredDate
didn't load to the view? But If I add type="datetime"
, the data is loaded. The problem is, DateTime
picker dropdown is not appears.
1st pic is without type="datetime"
and 2nd pic is with type="datetime"
(notice there's no datetime picker icon on it).
please advice.
thank you.
CodePudding user response:
in your customer class add Datatype to RegisteredDate like this
public class Customer
{
[Key]
public int CustomerId { get; set; }
public string CustomerName { get; set; }
[DataType(DataType.Date)]
public DateTime RegisteredDate { get; set; }
}