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

[Solved] MVC Grid validation with EqualToAttribute allways fails on Edit

0 Answers 21 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Somename
Top achievements
Rank 1
Somename asked on 12 Jun 2011, 07:48 AM
MVC Grid validation with EqualToAttribute allways fails - shows that 'PasswordConfirm' and 'Password' do not match. (fails client side, server controller action isn't hit). FF4.0.1, IE9

public class PersonViewModel
    {
        [Key]
        public int Id { get; set; }
 
        [Required]
        [Email]
        public string Email { get; set; }
 
        [Required]
        public string Password { get; set; }
 
        [Required]
        [EqualTo("Password")]
        public string PasswordConfirm { get; set; }
 
        [Url]
        public string HomePage { get; set; }
 
        [Integer]
        [Min(1)]
        public int Age { get; set; }
    }

View:
@using Telerik.Web.Mvc.UI
@model IEnumerable<TelerikMvc.Models.PersonViewModel>
@{
    ViewBag.Title = "PersonList";
}
<h2>
    PersonList</h2>
<p>
    @Html.ActionLink("Create New", "Create")
</p>
@{
    Html.Telerik().Grid(Model)
        .Name("GridPersons")
        .ToolBar(commands => commands.Insert())
        .DataKeys(cfg => cfg.Add(model => model.Id))
        .Columns(col =>
        {
            col.Command(cmd =>
            {
                cmd.Edit();
                cmd.Delete();
            }).Width(200);
            col.Bound(o => o.Id);
            col.Bound(o => o.Email);
            col.Bound(o => o.HomePage);
            col.Bound(o => o.Password);
            col.Bound(o => o.PasswordConfirm);
        })
    .Sortable()
    .EnableCustomBinding(true)
    .Pageable(cfg => cfg.PageSize(5).Total((int)ViewData["total"]))
    .DataBinding(db => db.Ajax()
        .Select("_AjaxSelectAction", "Home")
        .Update("_AjaxUpdateAction", "Home")
        .Delete("_AjaxDeleteAction", "Home")
        .Insert("_AjaxInsertAction", "Home"))
    .Render();
}

Controller (fragment):
[GridAction(EnableCustomBinding = true)]
 public ActionResult _AjaxUpdateAction(int id)
 {
     var person = Persons.Where(x => x.Id == id).SingleOrDefault();
     if (TryUpdateModel(person))
     {
         //some saving method
     }
     return View(new GridModel { Data = GetData(new GridCommand()), Total = 500 });
 }
Tags
Grid
Asked by
Somename
Top achievements
Rank 1
Share this question
or