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

Model Validation with Multiple Grids in TabStrip Control

1 Answer 55 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Vikram
Top achievements
Rank 1
Vikram asked on 03 Mar 2011, 06:51 AM
Hi,
       I have an MVC application with a view which has a Telerik TabStrip Control. The TabStrip has 3 tabs: the First tab contains three Telerik Grids, and the other two tabs one grid each.  All The values which are being bound to the grid are being validated in the Model. Each of the grids has Edit button present in each row. After editing the fields in the grid's row when insert/ save is clicked, the model validation is supposed to be fired stopping from executing the code in the controller. The problem is that validation works only for the first grid of the first tab and not for the remaining 4 grids in the View .  Below is the code

VIEW:
 <% Html.Telerik().TabStrip()
           .Name("captabletab")
           .Items(tabstrip =>
           {
               
               tabstrip.Add()
               .Text("Tab1")
                .Content(() =>
                {%>
                    <br />
                    <span class="..."></span>
                    <br />
                    <br />
                    <div>
                        <% Html.Telerik().Grid(Model.Class1)
                        .Name("Name1")

                        .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.ImageAndText).ImageHtmlAttributes(new { style = "margin-left:0" }))
                        .DataKeys(keys => keys.Add(c => c.ID))
                        .DataBinding(binding => binding.Server()
                        .Select("...", "...")
                        .Insert("....", "CapTable", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText })
                        .Update(".....", "CapTable", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText })
                        .Delete("....", "CapTable", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText })
                        )
                        .Columns(columns =>
                         {
                             columns.Bound(p => p.Col1).Width(250);
                             columns.Bound(p => p.Col2).Width(100);
                             columns.Bound(p => p.Col3).Width(100);
                             columns.Command(commands =>
                             {
                                 commands.Edit().ButtonType(GridButtonType.ImageAndText);
                                 commands.Delete().ButtonType(GridButtonType.ImageAndText);
                             }).HtmlAttributes(new { nowrap = "nowrap", style = "white-space:nowrap !important;" }).Width(300).Title("");
                         })
                         .HtmlAttributes(new { style = "overflow-x:auto;overflow-y:hidden" })
                         .Resizable(re => re.Columns(true))
                         .Scrollable()
                         .Editable(editing => editing.Mode(GridEditMode.InLine))
                         .Pageable().Render();
        
                        %>
                        <br />
                    </div>
                    <span class="....">....</span>
                    <br />
                    <br />
                    <div>
                        <% Html.Telerik().Grid(Model.Class2)
                        .Name("....")
                        
                        .DataKeys(keys => keys.Add(c => c.ID))
                        .DataBinding(binding => binding.Server()
                         .Select("...", "....")
                        .Update("...", "....", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText })
                        )
                        .Columns(columns =>
                         {
                             columns.Bound(p => p.Col1).Width(250);
                             columns.Bound(p => p.Col2).Width(100);
                             columns.Bound(p => p.Col3).Width(100);
                             columns.Command(commands =>
                             {
                                 commands.Edit().ButtonType(GridButtonType.ImageAndText);
                             }).HtmlAttributes(new { nowrap = "nowrap", style = "width:350px !important;white-space:nowrap !important;" }).Width(300).Title("");
                         })
                         .HtmlAttributes(new { style = "overflow-x:auto;overflow-y:hidden" })
                         .Scrollable()
                         .Resizable(re => re.Columns(true))
                         .Editable(editing => editing.Mode(GridEditMode.InLine))
                        .Pageable()
                        .Render();
                        %>
                        <br />
                    </div>
                    <span class="...">...</span>
                    <br />
                    <br />
                    <div>
                        <% Html.Telerik().Grid(Model.Class3)
                        .Name("...")
                       
                        .DataKeys(keys => keys.Add(c => c.ID))
                        .DataBinding(binding => binding.Server()
                        .Select("..", "...")
                        .Update("....", ".....", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText })
                        )
                        .Columns(columns =>
                         {
                             columns.Bound(p => p.Col1).Width(250);
                             columns.Bound(p => p.Col2).Width(100);
                             columns.Command(commands =>
                             {
                                 commands.Edit().ButtonType(GridButtonType.ImageAndText);
                             }).HtmlAttributes(new { nowrap = "nowrap", style = "width:350px !important;white-space:nowrap !important;" }).Width(300).Title("");
                         })
                         .HtmlAttributes(new { style = "overflow-x:auto;overflow-y:hidden" })
                         .Scrollable()
                         .Editable(editing => editing.Mode(GridEditMode.InLine))
                        .Pageable()
                           .Resizable(re => re.Columns(true))
                        .Render();
                        %>
                        <br />
                    </div>
                    <%});
               tabstrip.Add()
               .Text("Tab2")
               .Content(() =>
               {%>
                    <% Html.Telerik().Grid(Model.Class4)
                        .Name("....")
                        
                        .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.ImageAndText).ImageHtmlAttributes(new { style = "margin-left:0"}))
                        .DataKeys(keys => keys.Add(c => c.ID))
                        .DataBinding(binding => binding.Server()
                        .Select("...", "....")
                        .Insert("....", "....", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText })
                        .Update("....", ".....", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText })
                        .Delete("....", "....", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText })
                        )
                        .Columns(columns =>
                        {
                            columns.Bound(p => p.Col1).Width(220);
                             columns.Bound(p => p.Col2).Width(150);
                             columns.Command(commands =>
                             {
                                 commands.Edit().ButtonType(GridButtonType.ImageAndText);
                                 commands.Delete().ButtonType(GridButtonType.ImageAndText);
                             }).HtmlAttributes(new { nowrap = "nowrap", style = "width:350px !important;white-space:nowrap !important;" }).Width(300).Title("");
                        })
                        .Editable(editing => editing.Mode(GridEditMode.InLine))
                        .Pageable()
                        .Scrollable()
                        .Resizable(re => re.Columns(true))
                        .Render();
                    %>
                <%});
                tabstrip.Add()
                .Text("Tab3")
                .Content(() =>
                {%>
                    <% Html.Telerik().Grid(Model.Class5)
                        .Name("...")
                       
                        .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.ImageAndText).ImageHtmlAttributes(new { style = "margin-left:0"}))
                        .DataKeys(keys => keys.Add(c => c.ID))
                        .DataBinding(binding => binding.Server()
                        .Select("...", "...")
                        .Insert("....", "....", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText })
                        .Update("....", "....", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText })
                        .Delete(".....", "CapTable", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText })
                        )
                        .Pageable()
                        .Selectable()
                        .Columns(columns =>
                            {
                                columns.Bound(c => c.Col1).Width(300);
                                columns.Bound(c => c.Col2).Width(100);
                                columns.Bound(c => c.Col3).Width(100);
                                columns.Command(commands =>
                                {
                                    commands.Edit().ButtonType(GridButtonType.ImageAndText);
                                    commands.Delete().ButtonType(GridButtonType.ImageAndText);
                                }).HtmlAttributes(new { nowrap = "nowrap", style = "width:350px !important;white-space:nowrap !important;" }).Width(300).Title("");
                            })
                             .Editable(editing => editing.Mode(GridEditMode.InLine))
                           .Resizable(re => re.Columns(true))
                        .Render();
                    %>
                <%});
           })
           .SelectedIndex(((int)ViewData["SelectedIndex"]))
           .Render();



My MODEL has the classes - Class1, Class2, Class3, Class4, Class5 with properties which have validation using Attributes . Sample below:

public class Class1
    {

        public int ID { get; set; }

        [DisplayName("Column1")]
        [Required(ErrorMessage = "The Column1 field is required")]
        [RegularExpression(@"\b\d+\b", ErrorMessage = "The Column1 field should be a Positive Integral Value.")]
        public int Col1{ get; set; }

        [DisplayName("Column2")]
        [StringLength(20, ErrorMessage = "The length of Column2 should be less than 20 characters.")]
        [Required(ErrorMessage = "The Column2 is Required.")]
        public string Col2{ get; set; }




 

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 09 Mar 2011, 08:23 AM
Hello Vikram,

It seems to me that your question is related to our MVC suite. As it is supported by another team and questions about it are posted in another forum, if I am correct, please post your enquiry in the following forum:
ASP.NET MVC

Greetings,
Tsvetina
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Calendar
Asked by
Vikram
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or