batch mode appear validations

6 posts, 0 answers
  1. Daniel
    Daniel avatar
    192 posts
    Member since:
    Mar 2012

    Posted 19 Mar 2013 Link to this post

    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
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 21 Mar 2013 Link to this post

    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!
  3. Daniel
    Daniel avatar
    192 posts
    Member since:
    Mar 2012

    Posted 22 Mar 2013 Link to this post

    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
  4. Daniel
    Daniel avatar
    192 posts
    Member since:
    Mar 2012

    Posted 22 Mar 2013 Link to this post

    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
  5. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 26 Mar 2013 Link to this post

    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!
  6. Daniel
    Daniel avatar
    192 posts
    Member since:
    Mar 2012

    Posted 03 Apr 2013 Link to this post

    Ok,thank you for the explanations and links.
Back to Top