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

Invalid Template error in the detail/child of a Hierarchy Grid when trying to implement updating

2 Answers 11 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Laura
Top achievements
Rank 1
Veteran
Laura asked on 09 Jan 2021, 12:25 AM

Another 'Invalid Template' error ... there are tons out there, and I thought I'd find my answer, but no.

The hierarchy (nested) grid below works great until I uncomment line 58 or 67.  Then I get the invalid template error.

I've escaped my hash symbols on line 52 as I read in a ton of other posts.

Does anyone spot anything amiss???

TIA

001.@(Html.Kendo().Grid<OrgViewModel>()
002.    .Name("Grid")
003.    .Columns(columns =>
004.    {
005.        columns.Bound(e => e.OrgType).Hidden(true);
006.        columns.Bound(e => e.OrgId).Hidden(true);
007.        columns.Bound(e => e.OrganizationType).Title("Partner or Charter");
008.        columns.Bound(e => e.OrgName).Title("Name");
009.    })
010.    .Filterable(filterable => filterable
011.        .Extra(false)
012.        .Operators(operators => operators
013.            .ForString(str => str.Clear()
014.                .StartsWith("Starts with")
015.                .IsEqualTo("Is equal to")
016.                .IsNotEqualTo("Is not equal to")
017.            ))
018.    )
019.    .Groupable()
020.    .Pageable(m => m.PageSizes(new[] { "20", "50", "100", "All" }))
021.    .Resizable(resizable => resizable.Columns(true))
022.    .Sortable()
023.    .Scrollable(s => s.Enabled(true))
024.    .ClientDetailTemplateId("template")
025.    .HtmlAttributes(new { style = "height:850px;" })
026.    .DataSource(dataSource => dataSource
027.        .Ajax()
028.        .PageSize(20)
029.        .Read(read => read.Action("Orgs_Read", "FiscalContacts"))
030.        .Sort(sort =>
031.        {
032.            sort.Add(x => x.OrgName);
033.            sort.Add(x => x.OrgType);
034.        })
035.    )
036.    .Events(events => events.DataBound("dataBound"))
037.    )
038. 
039.@section scripts {
040.<script id="template" type="text/kendo-tmpl">
041.    @(Html.Kendo().Grid<FiscalContactViewModel>()
042.        .Name("Grid_#=OrgType#_#=OrgId#") // template expression, to be evaluated in the master context
043.        .Columns(columns =>
044.        {
045.            //columns.Command(command => { command.Edit(); }).Width(250);
046.            columns.Bound(o => o.Id).Hidden(true);
047.            columns.Bound(o => o.SalesforceId).Hidden(true);
048.            columns.Bound(o => o.LastName);
049.            columns.Bound(o => o.FirstName);
050.            columns.Bound(o => o.Title);
051.            columns.Bound(o => o.Email);
052.            columns.Bound(x => x.ExecComm).Title("Exec").Width(75).Filterable(true).ClientTemplate("\\#=ExecComm ? 'Yes': ''\\#").HtmlAttributes(new { style = "text-align:center" });
053.            columns.Bound(o => o.Roles);
054.            columns.Bound(o => o.FiscalPermissions).Title("Perms").Width(75);
055.        })
056.        .ToolBar(tools =>
057.        {
058.            //tools.Create();
059.            tools.Excel();
060.        })
061.        .Excel(excel => excel
062.            .FileName("Fiscal Contacts.xlsx")
063.            .Filterable(true)
064.            .AllPages(true)
065.            .ProxyURL(Url.Action("Excel_Export_Save", "FiscalContacts"))
066.        )
067.       
001.@(Html.Kendo().Grid<OrgViewModel>()
002.    .Name("Grid")
003.    .Columns(columns =>
004.    {
005.        columns.Bound(e => e.OrgType).Hidden(true);
006.        columns.Bound(e => e.OrgId).Hidden(true);
007.        columns.Bound(e => e.OrganizationType).Title("Partner or Charter");
008.        columns.Bound(e => e.OrgName).Title("Name");
009.    })
010.    .Filterable(filterable => filterable
011.        .Extra(false)
012.        .Operators(operators => operators
013.            .ForString(str => str.Clear()
014.                .StartsWith("Starts with")
015.                .IsEqualTo("Is equal to")
016.                .IsNotEqualTo("Is not equal to")
017.            ))
018.    )
019.    .Groupable()
020.    .Pageable(m => m.PageSizes(new[] { "20", "50", "100", "All" }))
021.    .Resizable(resizable => resizable.Columns(true))
022.    .Sortable()
023.    .Scrollable(s => s.Enabled(true))
024.    .ClientDetailTemplateId("template")
025.    .HtmlAttributes(new { style = "height:850px;" })
026.    .DataSource(dataSource => dataSource
027.        .Ajax()
028.        .PageSize(20)
029.        .Read(read => read.Action("Orgs_Read", "FiscalContacts"))
030.        .Sort(sort =>
031.        {
032.            sort.Add(x => x.OrgName);
033.            sort.Add(x => x.OrgType);
034.        })
035.    )
036.    .Events(events => events.DataBound("dataBound"))
037.    )
038. 
039.@section scripts {
040.<script id="template" type="text/kendo-tmpl">
041.    @(Html.Kendo().Grid<FiscalContactViewModel>()
042.        .Name("Grid_#=OrgType#_#=OrgId#") // template expression, to be evaluated in the master context
043.        .Columns(columns =>
044.        {
045.            //columns.Command(command => { command.Edit(); }).Width(250);
046.            columns.Bound(o => o.Id).Hidden(true);
047.            columns.Bound(o => o.SalesforceId).Hidden(true);
048.            columns.Bound(o => o.LastName);
049.            columns.Bound(o => o.FirstName);
050.            columns.Bound(o => o.Title);
051.            columns.Bound(o => o.Email);
052.            columns.Bound(x => x.ExecComm).Title("Exec").Width(75).Filterable(true).ClientTemplate("\\#=ExecComm ? 'Yes': ''\\#").HtmlAttributes(new { style = "text-align:center" });
053.            columns.Bound(o => o.Roles);
054.            columns.Bound(o => o.FiscalPermissions).Title("Perms").Width(75);
055.        })
056.        .ToolBar(tools =>
057.        {
058.            //tools.Create();
059.            tools.Excel();
060.        })
061.        .Excel(excel => excel
062.            .FileName("Fiscal Contacts.xlsx")
063.            .Filterable(true)
064.            .AllPages(true)
065.            .ProxyURL(Url.Action("Excel_Export_Save", "FiscalContacts"))
066.        )
067.        //.Editable(editable => editable.Mode(GridEditMode.InCell))
068.        .DataSource(dataSource => dataSource
069.            .Ajax()
070.            .PageSize(10)
071.            .Read(x => x.Action("ListContacts", "FiscalContacts", new { orgType = "#=OrgType#", orgId = "#=OrgId#" }))
072.            .Create(x => x.Action("FiscalContacts_Create", "FiscalContacts", new { orgType = "#=OrgType#", orgId = "#=OrgId#" }))
073.            .Update(x => x.Action("FiscalContacts_Update", "FiscalContacts"))
074.            .Model(model =>
075.            {
076.                model.Id(x => x.Id);
077.                model.Field(x => x.Id).Editable(false);
078.                model.Field(x => x.FiscalPermissions).Editable(false);
079.            }).Sort(sort =>
080.            {
081.                sort.Add(x => x.LastName);
082.                sort.Add(x => x.FirstName);
083.            })
084.        )
085.        .Filterable(filterable => filterable
086.            .Extra(false)
087.            .Operators(operators => operators
088.                .ForString(str => str.Clear()
089.                    .StartsWith("Starts with")
090.                    .IsEqualTo("Is equal to")
091.                    .IsNotEqualTo("Is not equal to")
092.                ))
093.        )
094.        .Groupable()
095.        .HtmlAttributes(new { style = "height:600px;" })
096.        .Pageable(m => m.PageSizes(new[] { "20", "50", "100", "All" }))
097.        .Resizable(resizable => resizable.Columns(true))
098.        .Sortable()
099.        .Scrollable(s => s.Enabled(true))
100.        .ToClientTemplate()
101.    )
102.</script>
103.    <script>
104.        function dataBound() {
105.            this.expandRow(this.tbody.find('tr.k-master-row').first());
106.        }
107.</script>
108.}
.Editable(editable => editable.Mode(GridEditMode.InCell))
068.        .DataSource(dataSource => dataSource
069.            .Ajax()
070.            .PageSize(10)
071.            .Read(x => x.Action("ListContacts", "FiscalContacts", new { orgType = "#=OrgType#", orgId = "#=OrgId#" }))
072.            .Create(x => x.Action("FiscalContacts_Create", "FiscalContacts", new { orgType = "#=OrgType#", orgId = "#=OrgId#" }))
073.            .Update(x => x.Action("FiscalContacts_Update", "FiscalContacts"))
074.            .Model(model =>
075.            {
076.                model.Id(x => x.Id);
077.                model.Field(x => x.Id).Editable(false);
078.                model.Field(x => x.FiscalPermissions).Editable(false);
079.            }).Sort(sort =>
080.            {
081.                sort.Add(x => x.LastName);
082.                sort.Add(x => x.FirstName);
083.            })
084.        )
085.        .Filterable(filterable => filterable
086.            .Extra(false)
087.            .Operators(operators => operators
088.                .ForString(str => str.Clear()
089.                    .StartsWith("Starts with")
090.                    .IsEqualTo("Is equal to")
091.                    .IsNotEqualTo("Is not equal to")
092.                ))
093.        )
094.        .Groupable()
095.        .HtmlAttributes(new { style = "height:600px;" })
096.        .Pageable(m => m.PageSizes(new[] { "20", "50", "100", "All" }))
097.        .Resizable(resizable => resizable.Columns(true))
098.        .Sortable()
099.        .Scrollable(s => s.Enabled(true))
100.        .ToClientTemplate()
101.    )
102.</script>
103.    <script>
104.        function dataBound() {
105.            this.expandRow(this.tbody.find('tr.k-master-row').first());
106.        }
107.</script>
108.}

2 Answers, 1 is accepted

Sort by
0
Laura
Top achievements
Rank 1
Veteran
answered on 10 Jan 2021, 01:26 AM
I apologize for posting the code twice.
0
Laura
Top achievements
Rank 1
Veteran
answered on 11 Jan 2021, 01:12 AM

I'VE FIGURED IT OUT!

After three days of staring at this I started commenting out code line-by-line.  The culprit was line 51 - the Email column.  That led me to check my view model for the attributes, and sure enough:

        [Required]
        [StringLength(100)]
        [RegularExpression(CommonConstants.EmailRegex, ErrorMessage = "Please enter a valid email address.")]
        public string Email { get; set; }

And in CommonConstants.cs:

        public const string EmailRegex = @"^[-!#$%&'*+/0-9=?A-Z^_a-z{|}~](\.?[-!#$%&'*+/0-9=?A-Z^_a-z{|}~])*@[a-zA-Z](-?[a-zA-Z0-9])*(\.[a-zA-Z](-?[a-zA-Z0-9])*)+$";

GOOD GRIEF!

Tags
Grid
Asked by
Laura
Top achievements
Rank 1
Veteran
Answers by
Laura
Top achievements
Rank 1
Veteran
Share this question
or