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

Batch Editing Validation Fails

3 Answers 206 Views
Grid
This is a migrated thread and some comments may be shown as answers.
adam
Top achievements
Rank 1
adam asked on 22 Jul 2014, 09:57 PM
I have tried following the Validation Guide and the Batch Editing example but something is still amiss. The validation tooltip does not appear when I attempt to Save Changes after leaving a required field empty (i.e. Rate). We are using ASP.NET MVC 4 Razor and Kendo UI 2014.1.415.

CSHTML
@(Html.Kendo().Grid<IncentiveViewModel>()
      .Name("Incentive")
      .Columns(columns =>
      {
          columns.Bound(p => p.Make).EditorTemplateName("MakeDropDown").Sortable(true);
          columns.Bound(p => p.Model).EditorTemplateName("ModelDropDown").Sortable(true);
          columns.Bound(p => p.Year).Sortable(true);
          columns.Bound(p => p.Term);
          columns.Bound(p => p.Rate);
          columns.Bound(p => p.StartDate).Format("{0:MM/dd/yyyy}").EditorTemplateName("CalendarPicker");
          columns.Bound(p => p.EndDate).Format("{0:MM/dd/yyyy}");
          columns.Template(@<text></text>)
              .Width(110)
              .ClientTemplate(@"<a class=""k-grid-delete"" href=""\#""></a>");
      })
      .ToolBar(toolbar =>
      {
          toolbar.Create().Text("Add Incentive");
          toolbar.Save().SaveText("Save Changes").CancelText("Cancel Changes");
      })
      .Editable(editable => editable.Mode(GridEditMode.InCell))
      .Resizable(resize => resize.Columns(true))
      .Pageable(pageable => pageable
          .Refresh(true)
          .PageSizes(true)
          .ButtonCount(10))
      .Navigatable()
      .Sortable()
      .Resizable(resize => resize.Columns(true))
      .DataSource(dataSource => dataSource
          .Ajax()
          .Batch(true)
          .PageSize(10)
          .ServerOperation(false)
          .Model(model =>
          {
              model.Id(p => p.IncentiveId);
              model.Field(p => p.Year).Editable(true);
              model.Field(p => p.Make).Editable(true);
              model.Field(p => p.Model).Editable(true);
              model.Field(p => p.Rate).Editable(true);
              model.Field(p => p.StartDate).Editable(true);
              model.Field(p => p.EndDate).Editable(true);
          })
          .Create("Create", "Incentive")
          .Read("Read", "Incentive")
          .Update("Update", "Incentive")
          .Destroy("Destroy", "Incentive"))
      )


ViewModel (abbreviated with just one field)
[Display(Name = "Rate")]
[Required(AllowEmptyStrings = false, ErrorMessageResourceType = typeof(Resources.Resources), ErrorMessageResourceName = "FieldRequired")]
[Range(0, 12, ErrorMessage = "Value for {0} must be between {1} and {2}.")]
public decimal? Rate { get; set; }

I noticed that no validation attributes are being appended to the input field:
<input class="text-box single-line" id="Rate" name="Rate" type="text" value="" data-bind="value:Rate">


What am I missing? What more do you need to see? Thanks.

Adam

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 24 Jul 2014, 11:40 AM
Hi Аdam,

I'm afraid that it is not obvious what may be the cause for the issue in question by looking at the provided details. However, could you please verify that the client validation as well as unobtrusive JavaScript features of ASP.NET MVC are enabled. Those are configured globally via the web.config appSetting element:

<appSettings>
  <add key="ClientValidationEnabled" value="true" />
  <add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>


Regards,
Rosen
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
adam
Top achievements
Rank 1
answered on 24 Jul 2014, 05:00 PM
Rosen, that indeed was the problem. UnobtrusiveJavaScriptEnabled was false in web.config. I brought this to the attention of another developer and he informed me it is false because it prevented MVC's standard validation from functioning -- ValidationSummary and ValidationHtmlMessageFor messsages would not appear when UnobtrusiveJavaScriptEnabled was true. We're not sure why this is the case. Any ideas?
0
Rosen
Telerik team
answered on 25 Jul 2014, 07:56 AM
Hi Adam,

Most probably ValidationSummary and ValidationHtmlMessageFor are not working when UnobtrusiveJavaScriptEnabled  is enabled due to missing JavaScript files, thus I suspect that you are currently using the ASP.NET MVC 2 validation. Information on unobtrusive client-side validation can be found here.

Note that Kendo UI Validator integration with ASP.NET MVC framework depends on the fact that ASP.NET MVC will generate the validation rules as attributes, thus the UnobtrusiveJavaScriptEnabled  should be enabled.

Regards,
Rosen
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
adam
Top achievements
Rank 1
Answers by
Rosen
Telerik team
adam
Top achievements
Rank 1
Share this question
or