[CLOSED] MVC conditional validation not showing error

  1. #1

    [CLOSED] MVC conditional validation not showing error

    Hi, I have a grid that uses popup editor to insert new row. I created a RequiredIfValidator and attach it to model field :

    public Class JobModel
    {
    
            [DisplayName("Email")]
            public bool SendEmailFlag { get; set; }
    
            [DisplayName("Subject")]
            [StringLength(80)]
            [RequiredIf("SendEmailFlag", true, ErrorMessage = "You must specify the Email Subject if Send Email is true")]
            public string EmailSubject { get; set; }
    
    }
    cshtml:

    @(Html.Kendo().Grid<JobModel> () 
             .Name("JobGrid")
             .HtmlAttributes(new { style = "height:700px;" })
             .Editable(editing => editing.Mode(GridEditMode.PopUp)
                                         .CreateAt(0)
                                         .DisplayDeleteConfirmation (false))
             .ToolBar(toolbar => toolbar.Create().Text("Add"))
             .Columns(columns =>
             {
                 columns.Bound(e => e.JobID).Hidden(true);
                 columns.Bound(e => e.JobDesc);
                 columns.Bound(e => e.SendEmailFlag)
                      .HeaderTemplate(@<text>
                          <a href="#" data-toggle="tooltip" title="Email Notification Enabeld" tabindex ="-1" >
                               <img src = "Images/Email.icon.png" /> </a>                    
                          </text>
                      ).Width("4%")
                      .Filterable(false)
                      .ClientTemplate("<input type='checkbox' disabled='disabled' name='SendEmailFlag' #: SendEmailFlag? checked='checked' : '' # />")
                      .HtmlAttributes(new { style = "text-align:center" });
                  columns.Bound(e => e.Runnable)
                      .HeaderTemplate(@<text>
                          <a href="#" data-toggle="tooltip" title="Ready to distribute -- has at least one group assigned." tabindex ="-1" >
                               <img src = "Images/ready.jpg" /> </a>                    
                          </text>
                     ).Width("4%")
                     .Filterable(false)
                     .ClientTemplate("<input type='checkbox' disabled='disabled' name='Runnable' #: Runnable? checked='checked' : '' # />")
                     .HtmlAttributes(new { style = "text-align:center" });
                  columns.Bound(e => e.CreateBy);
                  columns.Bound(e => e.LastModify).Format("{0:g}");
                  columns.Template(x => { })
                    .ClientTemplate("<a class='k-button' href='" + Url.Action("AddReport", "Job") + "/#=JobID#'>Assign Report</a> ");
    
                  columns.Command(commands =>
                  {
                      commands.Edit();
                      commands.Destroy();
                    
                  });
             })
            .Events (ev => 
                { ev.DataBound ("OnGridDataBound");
                  ev.Edit("OnEdit");
                })
            .ClientDetailTemplateId("JobDetailTemplate")
            .DataSource(dataBinding => dataBinding.Ajax()
                    .PageSize(20)
                    .Model(model => 
                        { model.Id(p => p.JobID);
                          model.Field(p => p.JobID).DefaultValue(Guid.Empty);
                          model.Field(p => p.CreateTime).Editable(false);
                          model.Field(p => p.LastModify).Editable(false);
                        })
                    .Read(read => read.Action("Job_Read", "Job"))
                    .Sort(sort => sort.Add(job => job.JobDesc))
                    .Update(update => update.Action("Job_Update", "Job"))
                    .Create(update => update.Action("Job_Insert", "Job"))
                    .Destroy(update => update.Action("Job_Delete", "Job"))
                    )
            .Pageable(p => p.Enabled(true).ButtonCount(5).PageSizes(new int[] {20, 40, 60, 100}).Refresh(true))
            .Filterable(f => f.Extra(false))
            .Resizable(resize => resize.Columns(true))
            .Sortable()
            .Scrollable()
           )
    The Validate() returns error but it never show the error under the filed like other Required validator.
    Did I missed something? what is best way to do conditional validation? I am using MVC 4
    Thanks
    -susan
    Last edited by Daniil; Jun 06, 2014 at 6:30 PM. Reason: Please use [CODE] tags, [CLOSED]
  2. #2
    Hi @susanz,

    Html.Kendo().Grid - is that Telerik?

Similar Threads

  1. UpdateContent function showing error
    By yash.kapoor in forum 2.x Help
    Replies: 2
    Last Post: Jan 10, 2013, 6:42 AM
  2. Replies: 2
    Last Post: Aug 19, 2011, 1:36 PM
  3. Always showing javascript error
    By vs.mukesh in forum 1.x Help
    Replies: 18
    Last Post: Mar 25, 2011, 5:34 AM
  4. [CLOSED] Javascript error when showing window (bug?)
    By Pablo_Azevedo in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Aug 25, 2010, 6:40 PM
  5. Hosting server with iis 6.0 showing Error.
    By Sreejith in forum 1.x Help
    Replies: 3
    Last Post: Sep 29, 2009, 5:27 AM

Tags for this Thread

Posting Permissions