Hello i am using Oracle Database and have a model called CableView Model that i pass to grid and CableInfoID is my intended id for the grid. I have issues updating grid data as always it returning 0 instead of a value.What am i doing wrong?
grid code
@(Html.Kendo().Grid<DI_IPMS_KENDO.Models.CableViewModel>()
.Name("CableNetGrid")
.Columns(columns =>
{
columns.Bound(p => p.CableInfoID);
columns.Bound(p => p.CableId).Title("Cable").Width(100);
columns.Bound(p => p.SwitchName).Width(100);
columns.Bound(p => p.Port).Width(100);
columns.Bound(p => p.TechnicianAssigned).Title("TechnicianAssigned").Width(150);
columns.Bound(p => p.AvailableIp).Width(100);
columns.Bound(p => p.SubnetMask).Width(100);
columns.Bound(p => p.Comments).Width(100);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.Pageable()
.Sortable()
.Scrollable()
.Events(ev => ev.Edit("onEdit"))
.Events(ev => ev.BeforeEdit("onEdit"))
.Events(ev => ev.Cancel("onCancel"))
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(p => p.CableInfoID);
model.Field(id => id.CableInfoID).DefaultValue(-1);
})
.Create(update => update.Action("Cables_Create", "Home").Data("getData"))
.Read(read => read.Action("Cables_Read", "Home").Data("getID"))
.Update(update => update.Action("Cables_Update", "Home").Data("getData"))
.Destroy(update => update.Action("Cables_Destroy", "Home"))
)
)
public class CableViewModel
{
[ScaffoldColumn(false) ]
public int CableInfoID { get; set; }
[Required]
[DisplayName("Cable ID")]
public string CableId { get; set; }
[Required]
[DisplayName("Switch Name")]
public string SwitchName { get; set; }
[Required]
[DisplayName("Port")]
public string Port { get; set; }
[ScaffoldColumn(false)]
public string ToolID { get; set; }
//public int ?ToolRecID { get; set; }
[ScaffoldColumn(false)]
public int ToolRecID { get; set; }
[UIHint("_AdminEmp")]
[Required]
[DisplayName("Technician Assigned")]
public string TechnicianAssigned { get; set; }
[DisplayName("Available IP")]
public string AvailableIp { get; set; }
[DisplayName("Subnet Mask")]
public string SubnetMask { get; set; }
[DisplayName("Gateway")]
public string Gateway { get; set; }
public string Comments { get; set; }
}
i have update method as follows ..please ignore other fields as i am returning from view or grid..
Everytime i try to update the grid row the CableInfoID is 0
public ActionResult Cables_Update([DataSourceRequest] DataSourceRequest request, CableViewModel product, int ToolRecID, string toolID, string Empltext)
{
if (ModelState.IsValid && product != null)
{
// Create a new Product entity and set its properties from the posted ProductViewModel.
var entity = new DiIpmsCableTeamCableInfo
{
RecordId = product.CableInfoID,
CableId = product.CableId,
SwitchName = product.SwitchName,
Port = product.Port,
TechnicianAssigned = Empltext,
ToolId = product.ToolID,
ToolRecId = ToolRecID,
AvailableIp=product.AvailableIp,
SubnetMask=product.SubnetMask
};
// Attach the entity.
_db.DiIpmsCableTeamCableInfos.Attach(entity);
// Change its state to Modified so Entity Framework can update the existing product instead of creating a new one.
_db.Entry(entity).State = EntityState.Modified;
// Or use ObjectStateManager if using a previous version of Entity Framework.
// northwind.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);
// Update the entity in the database.
_db.SaveChanges();
}
// Return the updated product. Also return any validation errors.
return Json(new[] { product }.ToDataSourceResult(request, ModelState));
}
In the grid update method