Home Kendo MVC Grid customized popup edit template validation not working
Reply: 0

Kendo MVC Grid customized popup edit template validation not working

Mic
1#
Mic Published in 2017-12-07 20:47:43Z

UsersManagement.cs

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace RDVMPortalDAL.Models
{
    public class UsersManagement
    {
        [Required(ErrorMessage = "Please enter First Name")]
        [RegularExpression("^[a-zA-Z]+$", ErrorMessage = "Please Enter only Alphabets for First Name")]
        public string FirstName { get; set; }
    }
}

UserManagement.cshtml

 @(Html.Kendo().Grid<RDVMPortalDAL.Models.UsersManagement>()
                .Name("UsersInfoGrid")
                .Columns(columns =>
                {
                    columns.Bound(c => c.FirstName);
                    columns.Bound(c => c.LastName);
                    columns.Bound(c => c.Address).ClientTemplate("#:Address#, #:City#, #:State# - #:Zip#");
                    columns.Bound(c => c.PhoneNumber);
                    columns.Bound(c => c.Email);
                    columns.Bound(c => c.UserName);
                    columns.Bound(c => c.Role);
                    columns.Bound(c => c.RegisteredBy);
                    columns.Command(commands => { commands.Edit(); });
                })
                .Sortable()
                .Pageable()
                .Groupable()
                .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("UsersDetailEditTemplate").Window(window=>window.Title("Edit User Information")))
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .Events(e => e.Sync("handlers"))
                    .Model(mods =>
                    {
                        mods.Id(c => c.UserId);
                        mods.Field(c => c.UserId).Editable(false);
                    })
                    .Read(read=>read.Action("ReadUsersInfoGrid", "Home"))
                    .Update(update=>update.Action("UpdateUsersInfoGrid","Home"))
                    .PageSize(20)
                )
        )

UsersDetailEditTemplate.cshtml

@model RDVMPortalDAL.Models.UsersManagement

@Html.HiddenFor(u => u.UserId)


<div class="row">
    @Html.Label("First Name : ", new { @class = "control-label col-sm-4 lbl" })
    <div class="col-sm-5 divs">
        @Html.TextBoxFor(u => u.FirstName, new { @class = "form-control inputcntrl" })
        @Html.ValidationMessageFor(u => u.FirstName, "", new { @class = "text-danger" })
    </div>
</div>

Controller

[HttpPost]
 public ActionResult UpdateUsersInfoGrid([DataSourceRequest]DataSourceRequest request, UsersManagement usersManagement
{
      if (ModelState.IsValid)
      {
          sqldal.UpdateUsersInfoData(usersManagement);
       }
       return Json(new[] { usersManagement }.ToDataSourceResult(request, ModelState));
}

So when I do edit from grid all things works good except validation so if I remove name sill it takes old data insted of showing ErrorMessage and does the update and when I debug the code Modelstate.Isvalid condition works perfectly but still not getting why Error message is not coming.

Any help please thank you .

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.260101 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO