Kendo Grid Popup - Missing ID

2 posts, 0 answers
  1. Tom
    Tom avatar
    7 posts
    Member since:
    Jan 2014

    Posted 20 May Link to this post

    I have a popup grid and I am using a template in Shared/EditorTemplates/_TeamSocial.cshtml.
    However when the popup opens the TeamID value @Model.TeamID = 0.

    How do I get the ID to pass over correctly?

     

    Grid code:

    @(Html.Kendo().Grid<BusinessApplication.DTO.DTOTeamSocialGrid>().Name("grid")
     
        .Columns(col =>
        {
            col.Bound(m => m.SocialCompanyName);
            col.Bound(m => m.SocialURL);
            col.Bound(m => m.CurrentStatus);
            col.Command(command => { command.Edit().HtmlAttributes(new { @class = "btn" }); }).Width(100);
            col.Command(command => { command.Destroy().HtmlAttributes(new { @class = "btn" }); }).Width(100);
             
        })
            .ToolBar(toolbar => toolbar.Create().Text("Add/Edit social link"))
        .Editable(editable => editable.Mode(GridEditMode.PopUp)
            .TemplateName("_TeamSocial")
            .Window(w => w.Width(600))
            .Window(w =>w.Title("Add/Edit social link")))  
        .Pageable()
        .Sortable()
        .Scrollable(s => s.Height("auto"))
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(20)
            .Events(events => events.Error("error_handler"))
            .Model(model => model.Id(m => m.TeamID))
            .Create(update => update.Action("TeamSocial_Create", "Team", new { teamID = Model.TeamID }))
            .Read(read => read.Action("GetTeamSocialGridItems", "Team", new { teamID = Model.TeamID }))
            .Update(update => update.Action("TeamSocial_Update", "Team", new { teamID = Model.TeamID }))
            .Destroy(update => update.Action("TeamSocial_Delete", "Team", new { teamID = Model.TeamID }))
        )
        )
        <script type="text/javascript">
            function error_handler(e) {
                if (e.errors) {
                    var message = "Errors:\n";
                    $.each(e.errors, function (key, value) {
                        if ('errors' in value) {
                            $.each(value.errors, function () {
                                message += this + "\n";
                            });
                        }
                    });
                    alert(message);
                }
            }
     
        </script>

     

    Template popup code:

    @model BusinessApplication.DTO.DTOTeamSocialGrid
     
    <!-- Social URL -->
    <div class="form-group required  col-xs-10 col-xs-offset-1">
        <span class="pull-right" data-toggle="tooltip"
              title="Enter the social website URL including 'http:// and the username'"
              data-placement="left">
            <i class="fa fa-question-circle"></i>
        </span>
     
        <label for="SocialURL">Social URL</label>
        <input type="text" class="form-control" id="SocialURL" placeholder="Enter the website URL (http://)" name="SocialURL"
               data-fv-notempty="true"
               data-fv-notempty-message="The social URL is required and cannot be empty"
               data-fv-uri="true"
               data-fv-uri-message="The social URL is not valid, it must start with http:// or https://">
    </div>
     
    <div class="clearfix"> </div>
    <div class="form-group  col-xs-10 col-xs-offset-1">
     
     
     
     
        <label class="checkbox">
            <input name="CurrentStatus" type="checkbox" id="CurrentStatus" @if (Model.CurrentStatus == BusinessApplication.Base.PPConstants.CurrentStatus.Active) { @: checked
                                                                                                                                                                                                                                                                                                                                                                               }> Set LIVE
        </label>
    </div>
     
     
    @Html.Hidden("TeamID", Model.TeamID)
    <div class="clearfix"> </div>

     

    Thanks 

    Tom

  2. Tom
    Tom avatar
    7 posts
    Member since:
    Jan 2014

    Posted 20 May in reply to Tom Link to this post

    OK looks like you can use on the grid:
    .AdditionalViewData(new { teamID = Model.TeamID })

    And pull on the Popup with:
    @ViewData["teamID"]

  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top