For instance, it might fire the create event on every CRUD event. I cannot say it is always the case, but it appears to normally be re-firing an event that was already fired (and processed).
My grid is bound to a ModelView for the and we actual do the update on the database model, but i always fill in the key on the object that was passed in and then return the modelView.
Below is an example of the grid in my view:
Example of my create method:
Thanks,
Logan
My grid is bound to a ModelView for the and we actual do the update on the database model, but i always fill in the key on the object that was passed in and then return the modelView.
Below is an example of the grid in my view:
@(
Html.Kendo().Grid<.Models.ConnectionView>()
.Name("ConnectionView")
.Columns(columns =>
{
columns.ForeignKey(c => c.ConnId, Model.All, "Value", "Text").Title("Restriction");
columns.Bound(c => c.MaxEnrollment);
columns.Command(command =>
{
command.Custom("move-up").Text("u").Click("OnMoveUp");//, "Home", new {Area="Sessions",id="#=Id#" });
command.Custom("move-down").Text("d").Click("OnMoveDown");//, "Home", new { Area = "Sessions", id = "#=Id#" });
command.Edit();
command.Destroy();
});
})
.Pageable(page =>
{
page.Enabled(true);
page.Input(false);
page.Numeric(false);
page.PreviousNext(true);
page.Messages(message => message.Empty("There are no records to show. Click the Add button to create a row"));
})
.ToolBar(toolbar => toolbar.Create().Text("Add"))
.Editable(editable => editable.Mode(GridEditMode.InLine))
.DataSource(dataSource => dataSource
.Ajax()
.Events(events =>
{
events.Error("error_handler");
})
.Model(model =>
{
model.Id(m => m.Id);
model.Field(m => m.ConnId).DefaultValue(int.Parse(Model.All.First().Value));
})
.Create(update => update.Action("ConnectionView_Create", "Home"))
.Read(read => read.Action("ConnectionView_Read", "Home"))
.Update(update => update.Action("ConnectionView_Update", "Home"))
.Destroy(update => update.Action("ConnectionView_Destroy", "Home"))
)
public ActionResult RestrictionConnectionView_Create([DataSourceRequest] DataSourceRequest request, RestrictionConnectionView connector)
{
var newConn = new OrientationSession_RestrictionConnector();
if (ModelState.IsValid)
{
var restrictionRepo = new EFRepository<
Restriction
>(_uow);
var restriction = restrictionRepo.GetByKey(connector.RestrictionId);
var repo = new EFRepository<
Conn
>(_uow);
var session = repo.WhereIncluding(w => w.Id == _WorkingSessionId, i => i.RestrictionConnectors).FirstOrDefault();
if (session != null && restriction != null)
{
newConn.OrientationSessionId = _WorkingSessionId;
newConn.Restriction = restriction;
newConn.MaxEnrollment = connector.MaxEnrollment;
newConn.CreatedBy = User.Identity.Name;
newConn.SequenceNumber = session.RestrictionConnectors == null || session.RestrictionConnectors.Count == 0 ? 1 : session.RestrictionConnectors.Max(m => m.SequenceNumber) + 1;
session.RestrictionConnectors.Add(newConn);
repo.Update(session);
_uow.Commit();
ResetSessionVars();
}
}
connector.Id = newConn.Id;
return Json(new[] { connector }.ToDataSourceResult(request, ModelState));
}
Thanks,
Logan