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

batch mode appear validations

5 Answers 135 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 19 Mar 2013, 03:32 PM
Hello,
i have a strange error when i am using the grid in batch mode.
even if i have all the values in the grid fields when i press the save changes button,it appears a message box with some required validation errors.I put some validations on the viewModel
something like this
[Required(ErrorMessageResourceType = typeof(Payroll.Resources.Resources),ErrorMessageResourceName = "ValidationMessage_Required")]
public string Name { get; set; }

indeed i put that javascript code
<script type="text/javascript">

function error_handler(e) {
if (e.errors) {
var message = "Errors:\n";
$.each(e.errors, function (key, value) {
if ('errors' in value) {
$.each(value.errors, function () {
message += this + "\n";
});
}
});
alert(message);
}
}
</script>
but the validations should active only if i do not have anything in the grid fields.

Why it appears those messages?what could be the error?

Regards,
Daniel

5 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 21 Mar 2013, 11:27 AM
Hello Daniel,

I am not sure I understand your question. The attribute that you have added is the Requred one and the validation message / error is added when there is no value provided for that field. What exactly is the expected behavior from your point of view? Could you also show us what exactly is the error message that you see?

Kind regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Daniel
Top achievements
Rank 1
answered on 22 Mar 2013, 09:24 AM
i have a grid where the batch mode is activated code of the view  looks like this:


@{
ViewBag.Title = "Measurements";
}

<h2>@ViewBag.Message</h2>


@(Html.Kendo().Grid<Payroll.ViewModels.TallyMeasurementViewModel>()
.Name("Grid")
.Columns(columns => {
columns.Bound(p => p.Code) ;
columns.Bound(p => p.Name) ;
columns.Bound(p => p.MaxLength).Title("Max length");
columns.Bound(p => p.IsActive);
columns.Bound(p => p.IsHour);
columns.Bound(p => p.Precision);
columns.Bound(p => p.Priority);
columns.Bound(p => p.Formula);
columns.Command(command => { command.Destroy().Text("Delete"); }).Width(200);
})
.ToolBar(toolbar =>
{
toolbar.Create().Text("Add");
toolbar.Save().SaveText("Save").CancelText("Cancel");
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Pageable()
.Sortable()
.Scrollable()

.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.PkTallyMeasurement))
.Create(update => update.Action("EditingInline_Create", "Home"))
.Read(read => read.Action("EditingInline_Read", "Home"))
.Update(update => update.Action("EditingInline_Update", "Home"))
.Destroy(update => update.Action("EditingInline_Destroy", "Home"))
)
)
<script type="text/javascript">
function error_handler(e) {
if (e.errors) {
var message = "Errors:\n";
$.each(e.errors, function (key, value) {
if ('errors' in value) {
$.each(value.errors, function () {
message += this + "\n";
});
}
});
alert(message);
}
}
</script>

the Problem is when i add a new record pressing on Add button,i fill out all the fields with values BUT,in the controller i have an empty viewModel and because i have required on 3 fields,it's normal to get this error message.but why do i have an empty model?

the action for Create is looking like this(in inline mode is called the same action,and it's working ok)
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditingInline_Create([DataSourceRequest] DataSourceRequest request, TallyMeasurementViewModel measurement)
{
if (measurement != null && ModelState.IsValid)
{
 
_tallyMeasurementRepository.Add(AutoMapper.Mapper.Map<TallyMeasurementViewModel,TallyMeasurement>(measurement));
}
 return Json(new[] { measurement }.ToDataSourceResult(request, ModelState));
}

I attached the running screen with the message,and the code behind from the controller.
Maybe i am missing some configuration to the grid in order to work in batch mode.

Regads,
Daniel
0
Daniel
Top achievements
Rank 1
answered on 22 Mar 2013, 02:34 PM
i think the problem is in the controller where i have to use [bind(prefix="model")].Why do i need this?
is something specific to kendo framework?

regards,
Daniel
0
Petur Subev
Telerik team
answered on 26 Mar 2013, 09:51 AM
Hello Daniel,

No this attribute is not specific to the Kendo framework but to the MVC framework. Please check the following articles which explain how collection of objects should be passed to a MVC action method so the default MVC Model BInder can fill-up the collection:


http://www.hanselman.com/blog/ASPNETWireFormatForModelBindingToArraysListsCollectionsDictionaries.aspx
http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx

Kind Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Daniel
Top achievements
Rank 1
answered on 03 Apr 2013, 07:34 AM
Ok,thank you for the explanations and links.
Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Daniel
Top achievements
Rank 1
Share this question
or