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

Error with Kendo Grid ClientTemplate

0 Answers 151 Views
Grid
This is a migrated thread and some comments may be shown as answers.
King
Top achievements
Rank 1
King asked on 02 Aug 2012, 09:07 PM
I get the error that the username variable is not defined.
Below is what is in the source:  I have tried various casing for the username.
When I get the undefined error, I can pass my variable, but I cannot page because of the error.
If I remove the error by making my variable all lowercase, the passed in variable is null.

function anonymous(data) {
var o,e=kendo.htmlEncode;with(data){o='<tr data-uid="'+(uid)+'"><td ><a href=\'/Admin/Admin/GetUserRoles/UserName='+(username)+'\'>'+(UserName)+'</a></td><td >'+(e(Email))+'</td><td >'+(e(IsApproved))+'</td><td >'+(e(IsLockedOut))+'</td><td >'+(e(IsOnline))+'</td><td >'+(e(LastLoginDate))+'</td></tr>';}return o;
}

My entire View is below:

@model IList<DsTow.Presentation.Areas.Admin.ViewModel.UserViewModel>
@using Kendo.Mvc.UI
@using DsTow.Presentation.Areas.Admin.ViewModel

@{
    ViewBag.Title = "Users";

    var rolesview = @ViewBag.RolesView;
}
<h2>
    Users</h2>
<div>
    <table>
        <tr>
            <td>
                @Html.ActionLink("All", "FindUsersByText", "Admin", new { area = "Admin", val = "All" }, null)
            </td>
            <td>
                @Html.ActionLink("A", "FindUsersByText", "Admin", new { area = "Admin", val = "A" }, null)
            </td>
            <td>
                @Html.ActionLink("B", "FindUsersByText", "Admin", new { area = "Admin", val = "B" }, null)
            </td>
            <td>
                @Html.ActionLink("C", "FindUsersByText", "Admin", new { area = "Admin", val = "C" }, null)
            </td>
            <td>
                @Html.ActionLink("D", "FindUsersByText", "Admin", new { area = "Admin", val = "D" }, null)
            </td>
            <td>
                @Html.ActionLink("E", "FindUsersByText", "Admin", new { area = "Admin", val = "E" }, null)
            </td>
            <td>
                @Html.ActionLink("F", "FindUsersByText", "Admin", new { area = "Admin", val = "F" }, null)
            </td>
            <td>
                @Html.ActionLink("G", "FindUsersByText", "Admin", new { area = "Admin", val = "G" }, null)
            </td>
            <td>
                @Html.ActionLink("H", "FindUsersByText", "Admin", new { area = "Admin", val = "H" }, null)
            </td>
            <td>
                @Html.ActionLink("I", "FindUsersByText", "Admin", new { area = "Admin", val = "I" }, null)
            </td>
            <td>
                @Html.ActionLink("J", "FindUsersByText", "Admin", new { area = "Admin", val = "J" }, null)
            </td>
            <td>
                @Html.ActionLink("K", "FindUsersByText", "Admin", new { area = "Admin", val = "K" }, null)
            </td>
            <td>
                @Html.ActionLink("L", "FindUsersByText", "Admin", new { area = "Admin", val = "L" }, null)
            </td>
            <td>
                @Html.ActionLink("M", "FindUsersByText", "Admin", new { area = "Admin", val = "M" }, null)
            </td>
            <td>
                @Html.ActionLink("N", "FindUsersByText", "Admin", new { area = "Admin", val = "N" }, null)
            </td>
            <td>
                @Html.ActionLink("O", "FindUsersByText", "Admin", new { area = "Admin", val = "O" }, null)
            </td>
            <td>
                @Html.ActionLink("P", "FindUsersByText", "Admin", new { area = "Admin", val = "P" }, null)
            </td>
            <td>
                @Html.ActionLink("Q", "FindUsersByText", "Admin", new { area = "Admin", val = "Q" }, null)
            </td>
            <td>
                @Html.ActionLink("R", "FindUsersByText", "Admin", new { area = "Admin", val = "R" }, null)
            </td>
            <td>
                @Html.ActionLink("S", "FindUsersByText", "Admin", new { area = "Admin", val = "S" }, null)
            </td>
            <td>
                @Html.ActionLink("T", "FindUsersByText", "Admin", new { area = "Admin", val = "T" }, null)
            </td>
            <td>
                @Html.ActionLink("U", "FindUsersByText", "Admin", new { area = "Admin", val = "U" }, null)
            </td>
            <td>
                @Html.ActionLink("V", "FindUsersByText", "Admin", new { area = "Admin", val = "V" }, null)
            </td>
            <td>
                @Html.ActionLink("W", "FindUsersByText", "Admin", new { area = "Admin", val = "W" }, null)
            </td>
            <td>
                @Html.ActionLink("X", "FindUsersByText", "Admin", new { area = "Admin", val = "X" }, null)
            </td>
            <td>
                @Html.ActionLink("Y", "FindUsersByText", "Admin", new { area = "Admin", val = "Y" }, null)
            </td>
            <td>
                @Html.ActionLink("Z", "FindUsersByText", "Admin", new { area = "Admin", val = "Z" }, null)
            </td>
        </tr>
    </table>
    <table>
        <tr>
            <td>
                <div id="Users_Container">
                    @(Html.Kendo().Grid(Model)
                       .Name("UserGrid")
                       .Columns(columns =>
                       {

                           columns.Template(
                            @<text>
                                    @Ajax.ActionLink(@item.UserName, "GetUserRoles", "Admin", new { username = @item.UserName },  new AjaxOptions{ UpdateTargetId="roleResults"}, null)
                           </text>).Title("User Name").ClientTemplate("<a href='/Admin/Admin/GetUserRoles/UserName=#=username#'>#=UserName#</a>"); causing error
                                                
                           columns.Bound(p => p.Email)
                          .Width(120)
                          .Title("Email");
                           columns.Bound(p => p.IsApproved)
                          .Width(120)
                          .Title("IsApproved");
                           columns.Bound(p => p.IsLockedOut)
                          .Width(120)
                          .Title("IsLockedOut");
                           columns.Bound(p => p.IsOnline)
                          .Width(120)
                          .Title("IsOnline");
                           columns.Bound(p => p.LastLoginDate)
                          .Width(120)
                          .Title("LastLoginDate");
                          
                       })
                         .DataSource(dataSource => dataSource
                         .Ajax() // Specify that the data source is of ajax type                                            
                         .Read(read => read.Action("Users_Read", "Admin", new { val = ViewBag.Val }).Data("additionalData"))// Specify the action method and controller name                                                  
                         .PageSize(2))
                         .Pageable())
                    <script type="text/javascript">
                        function additionalData() {
                            return {

                            };
                        }
                    </script>
                </div>
                <div>                   
                 <div id="roleResults" />                     
                </div>
            </td>
        </tr>
    </table>
</div>

My controller is below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Mvc;
using System.Web.Security;
using DsTow.Presentation.Repositories;
using DsTow.Presentation.Repositories.Core;
using AutoMapper;
using DsTow.Presentation.Areas.Admin.ViewModel;
using DsTow.Presentation.Infrastructure;
using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using DsTow.Presentation.Areas.Admin.Models;

namespace DsTow.Presentation.Areas.Admin.Controllers
{
    public class AdminController : DsTowBaseController
    {
        private IUserRepository usersRepository;
         
        public AdminController(IUserRepository usersRepository)
        {
            this.usersRepository = usersRepository;

        }

        public ActionResult Index()
        {
            return View();
        }
        //
        // GET: /Admin/Admin/

        public ActionResult FindUsersByText(string val)
        {
            ViewBag.Val = val;
            if (val != "All" && !string.IsNullOrEmpty(val))
            {
                MembershipUserCollection  users = this.usersRepository.FindUsersByText(val);


                IEnumerable<UserViewModel> userview =
                        Mapper.Map<IEnumerable<MembershipUser>, IEnumerable<UserViewModel>>(users.Cast<MembershipUser>().AsEnumerable());                
 
                return View("Users", userview);
            }
            else
            {
                MembershipUserCollection users = this.usersRepository.FindAllUsers();


                IEnumerable<UserViewModel> userview =
                   Mapper.Map<IEnumerable<MembershipUser>, IEnumerable<UserViewModel>>(users.Cast<MembershipUser>().AsEnumerable());
                

                return View("Users", userview);
            }

           
        }

        public PartialViewResult GetUserRoles(string username)
        {

            var results = this.usersRepository.GetUserRoles(username);  
            var result = Mapper.Map<IEnumerable<UserRoles>, IEnumerable<UserRolesViewModel>>(results.AsEnumerable());
            return PartialView("_UserDetails", result);            
        }
        //public ActionResult Roles_Read([DataSourceRequest]DataSourceRequest request, string val)
        //{

        //    MembershipUserCollection users = this.usersRepository.FindUsersByText(val);
        //    IEnumerable<UserViewModel> userview =
        //         Mapper.Map<IEnumerable<MembershipUser>, IEnumerable<UserViewModel>>(users.Cast<MembershipUser>().AsEnumerable());


        //    return Json(userview.FirstOrDefault().Roles.ToDataSourceResult(request, ModelState));
        //}

        public ActionResult Users_Read([DataSourceRequest]DataSourceRequest request, string val)
        {                        
            if (val != "All" && !string.IsNullOrEmpty(val))
            {
                MembershipUserCollection users = this.usersRepository.FindUsersByText(val);

                IEnumerable<UserViewModel> userview =
                        Mapper.Map<IEnumerable<MembershipUser>, IEnumerable<UserViewModel>>(users.Cast<MembershipUser>().AsEnumerable());
                return Json(userview.ToDataSourceResult(request, ModelState));                
            }
            else
            {
                MembershipUserCollection users = this.usersRepository.FindAllUsers();


                IEnumerable<UserViewModel> userview =
                   Mapper.Map<IEnumerable<MembershipUser>, IEnumerable<UserViewModel>>(users.Cast<MembershipUser>().AsEnumerable());

               
                return Json(userview.ToDataSourceResult(request, ModelState));               
            }
                       


        }


    }
}


I have no idea why this is occurring.  It looks right to me.  I think it is a bug in Kendo.

No answers yet. Maybe you can help?

Tags
Grid
Asked by
King
Top achievements
Rank 1
Share this question
or