This is a migrated thread and some comments may be shown as answers.

Problem with InLine in mvc grid

1 Answer 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Winnie
Top achievements
Rank 1
Winnie asked on 29 Apr 2013, 07:15 PM
I have this grid:
@(Html.Kendo().Grid<Payday.Website.Models.Message.MessageViewModel>()
.Name("Message")
.Columns(columns =>
{
columns.Bound(p => p.Id).Groupable(false);
columns.Bound(p => p.MessageType).ClientTemplate( "#= (MessageType.Name == null) ? ' ' :MessageType.Name #");
columns.Bound(p => p.Employee).ClientTemplate("#=Employee.FullName#");
columns.Bound(p => p.Responsible).ClientTemplate("#=Responsible.FullName#").EditorTemplateName("PayDayEmployee").Width(200);
columns.Bound(p => p.Sender).ClientTemplate("#=Sender.FullName#");
columns.Bound(p => p.SentDate).Format("{0:dd-MM-yyyy}");
columns.Command(command => command.Custom("Vis").Click("ShowMessage"));
columns.Command(command => command.Edit());
})
.ToolBar(toolBar =>
{
//toolBar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Groupable()
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.HtmlAttributes(new { style = "height:730px;" })
.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Error("error_handler"))
.Batch(false)
.PageSize(25)
.Model(model =>
{
model.Id(p => p.Id);
model.Field(p => p.Id).Editable(false);
model.Field(p => p.MessageType).Editable(false);
model.Field(p => p.Employee).Editable(false);
model.Field(p => p.Sender).Editable(false);
model.Field(p => p.SentDate).Editable(false);
})
.Read(read => read.Action("GetPayDayMessages", "Message"))
.Update(update => update.Action("UpdateMessages", "Message"))
)
)


I am able to enter edit mode and i can cancel it.
If i doesn't make any changes i can press update just fine.
If i make changes the changes are sent to the server but the grid remains in édit mode.
I can see i recieve a empty reply from the server and if there is an error in the data then i recieve the expected error message.
My server method looks like this:

 [AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateMessages([DataSourceRequest] DataSourceRequest request,
[Bind(Prefix = "models")]IEnumerable<MessageViewModel> messages)
{
if (messages != null && ModelState.IsValid)
{
foreach (var m in messages)
{
var message = _iMessageRepository.GetById(m.Id);
if (m.Responsible != null)
{
message.Responsible = EmployeeRepository.GetById(m.Responsible.Id);
}
else
{
message.Responsible = null;
}
_iMessageRepository.Save(message);
}
}
// return Json(messages.ToDataSourceResult(request, ModelState));
return Json(ModelState.ToDataSourceResult(), JsonRequestBehavior.AllowGet);
}
I include files like this:
<link href="@Url.Content("~/Content/kendo/2013.1.319/kendo.common.min.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/kendo/2013.1.319/kendo.dataviz.min.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/kendo/2013.1.319/kendo.default.min.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/kendo/2013.1.319/kendo.dataviz.default.min.css")" rel="stylesheet" type="text/css" />
<!--<script src="@Url.Content("~/Scripts/kendo/2013.1.319/jquery.min.js")"></script>-->
<script src="@Url.Content("~/Scripts/kendo/2013.1.319/kendo.all.min.js")"></script>
<script src="@Url.Content("~/Scripts/kendo/2013.1.319/kendo.aspnetmvc.min.js")"></script>
<script src="@Url.Content("~/Scripts/kendo.modernizr.custom.js")"></script>


Any ideas ?

1 Answer, 1 is accepted

Sort by
0
Winnie
Top achievements
Rank 1
answered on 30 Apr 2013, 02:47 AM
I managed to solve it using this code in my controller method.
return Json(ModelState.IsValid ? new object() : ModelState.ToDataSourceResult());
Tags
Grid
Asked by
Winnie
Top achievements
Rank 1
Answers by
Winnie
Top achievements
Rank 1
Share this question
or