In my Index
View for the list of of rows I put a EditorFor
instead of DisplayFor
for my field. I am trying to capture a Completion Date for my rows and then have the ability to Submit
all the rows that have a value. The field is a DateTime
and the DatePicker
for the fields work however, when I select a value in any row besides the first row it will change the value in the first row and does not place any value in the respective field.
Then I would like to click the Submit button and have it bring in the list and look for any Modifications to the record and record the change.
In my Index.cshtml i tried the following -
@for (var i = 0; i < Model.Count(); i++ )
{
@Html.EditorFor(modelItem => item.CompletionDate[i])
}
However it does not like item.CompletionDate[i]
. I receive Cannot apply index with [] to an expression of type System.DateTime?
Update:
My model
namespace AQB_MON.Models
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
public partial class PrevMaintenanceList
{
public int PrevMaintenanceListID { get; set; }
public int PreventativeMaintenanceID { get; set; }
public int DeviceTypeMaintenanceID { get; set; }
[Display(Name = "Completion Date")]
[DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
public DateTime? CompletionDate { get; set; }
}