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

[Solved] Grid validation in ajax detailview

3 Answers 138 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.
Andrew
Top achievements
Rank 1
Andrew asked on 22 Sep 2010, 11:09 AM
In spite of my success in getting validation to work in an ajax bound gridview  earlier  I find that it does not work correctly (in fact at all) in a detailview in a grid view. I've taken a simple "person with notes" test case

<%= Html.Telerik().Grid<TelTest.Models.Person>()
    .Name("Grid")
        .DataKeys(k => { k.Add(p => p.Id); })
    .DataBinding(db=> {
        db.Ajax()
            .Select("_selectAjax","Home")
            .Update("_updateAjax","Home");
    })
    .Columns(col=>{
        col.Bound(p=>p.FirstName);
        col.Bound(p=>p.Surname);
        col.Command(com => {
            com.Edit();
         
        });
    })
                    .DetailView(dv => dv.ClientTemplate(
                    Html.Telerik().Grid<TelTest.Models.Note>()
                        .Name("GUESTS_<#=Id #>")
                        .DataKeys(k => k.Add(c => c.Id))
                            .DataBinding(db => db.Ajax().Select("_AjaxNoteIndex", "Home", new { id = "<#= Id #>" }).Update("_AjaxNoteUpdateIndex", "Home").Insert("_AjaxNoteInsertIndex", "Home", new { id = "<#= Id #>" }))
                        .Editable(f => f.Enabled(true))
                        .ToolBar(commands => commands.Insert().ImageHtmlAttributes(new { style = "margin-left:0" }))
                        .Columns(c =>
                        {
                            c.Bound(n => n.Textnote).Width(220);
      
                            c.Command(com => { com.Edit(); });
                        })
                        .ToHtmlString()
                    ))
                     
    .Editable(ed=>ed.Mode(GridEditMode.InLine))   
     
    %>

Person is validated correctly, but Notes are not. Note [DisplayName] is honored, but the validation is not. I can see that TryUpdateModel adds errors to the modelstate when I update a note, however, I don't believe the ajax callback should even have fired if validation was working correctly. 

Help!

Andrew

3 Answers, 1 is accepted

Sort by
0
Ryan
Top achievements
Rank 1
answered on 09 Nov 2010, 02:58 PM
Have you had any luck figuring this out?  I'm having the same problem.  I know what's happening, I'm just not sure how to fix it.

The grid uses client validation that is bound to the form when the page is loaded.  When you load the detailview using ajax, the validation isn't being attached the the form.  We have to somehow  make this happen, but my question is how?
0
Andrew
Top achievements
Rank 1
answered on 09 Nov 2010, 03:06 PM
Sorry, no. I had two cases, for one  I relied on drop down lists to constrain user input and left it at that, the other I wrote my own grid editor from scratch.
0
Ryan
Top achievements
Rank 1
answered on 09 Nov 2010, 03:20 PM
ah thanks anyway.  This is insanely frustrating.  I spent 4 hours last night setting up an app that has 3 nested levels assuming validation would work in the DetailView without a problem... There's nothing I can really do to avoid validating these fields against a data annotation.  So now I have this really nice app that only validates in one place.
Tags
Grid
Asked by
Andrew
Top achievements
Rank 1
Answers by
Ryan
Top achievements
Rank 1
Andrew
Top achievements
Rank 1
Share this question
or