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

[Solved] Grid Cannot Postbox a List of CheckBoxes

0 Answers 44 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.
Jon
Top achievements
Rank 1
Jon asked on 12 Oct 2012, 04:16 PM
I am having some serious problems with the Telerik Grid that I need to resolve and my team has not been able to figure out how to correctly do this.  I think we are all just missing something so simple that we cannot see it.

What we have is a simple grid with a master/detail record.  In the master record is displayed as a parent row in the grid, the detail record is displayed as DetailView() in the grid.  In that detail view we have a edit template that we are using.  Here's that line of code.

.Editable(editing => editing.Mode(GridEditMode.PopUp)).Editable(editing => editing.TemplateName("EditTaskDetail"))

In the EditTaskDetail template we have a simple  for each loop that loops through a list of categories that we want to display as a list of checkboxes on the template.  We are passing that list in the viewbag because we do not need it in the model.  One solution I have considered is just adding it to the model.  But I am not sure how the Telerik grid handles that sort of thing. 

 

 

 

 

<div class="control-group">
        <div class="control-label">
            Categories
        </div>
        <div class="controls">
            <div style="height: 100px; width: 250px; background-color: #ffffff; overflow: auto;">
                <table width="100%">                                       
                    @foreach (var cat in ViewBag.Categories)
                    {
                        <tr>
                            <td>
                                <input type="checkbox" name="selectedObjects" value="@cat.Id"/> @cat.Description
                            </td>
                        </tr>
                    }
                </table>
            </div>
        </div>
    </div>

 

 

 

Now in a normal (non-Telerik Grid) view this would work fine.  The input box are created with all the same names.  So we'd get an array on the postback action containing a list of all of the checkbox that have been checked... or it may be an array of truee/false values indicating what is checked.  Since it has never worked, I don't actually know.  But other pages without the grid, this works fine.

However, we never get the array.  Well, we do but the values are very odd.  I suspect it is because the input checkbox are stored within the grid.  When you do a view source, the code is non standard and you can see that the grid is doing something here.

So my question is... how to I put a list of checkboxes on a grid's edit template, then post those back to my controller and get the values of those checkboxes? 

Here's what the action looks like.  What we would expect is that the array selectedObjects would contain a list of ids for the checkboxes that have been checked.  That is how a non-grid view would work.  What is the trick to get the grid to do this?  If it cannot, what options to be have to support a list of checkboxes in a grid's edit template?

 

 

 

[HttpPost]
        public virtual ActionResult UpdateTask(string[] selectedObjects, TaskDetailViewModel taskDetailViewModel)
        {
            var taskDetailModel = _mapper.Map<TaskDetailViewModel, TaskDetailModel>(taskDetailViewModel);
            _taskService.UpdateDetail(taskDetailModel);
            return View("Index");
        }

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