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

[Solved] Help getting values from checkboxes in Grid

2 Answers 24 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
superservo15
Top achievements
Rank 1
superservo15 asked on 12 Feb 2013, 05:36 PM
Hi,
I'm pretty new to MVC 4 and Razor (which is what we are now using at work) and I am just trying to make a little modal popup / partial view that contains a Telerik Grid Control with checkboxes and data. I can load the grid all fine and dandy, but have no idea HOW to get the list of selected Id's OUT of the grid or how the Server Side example on the website actually calls the proper controller action and passes in a list of int[] values?

What I want to do is either return this list of ID's to my parent page and save them in the parent's model or some other way of storing them to use for the parent Save.

Basically I set my grid up as per the example, but HOW do I get that controller bull jive to work?
Any help would be much appreciated :) Thanks.

@model MDL.ViewModels.

 

InstrumentSelectViewModel

 

@{ Html.BeginForm(); 
  
    @Html.ValidationSummary(true)
  
      
        @(Html.Telerik().Grid<MDL.Models.Instrument>(Model.Instruments)
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Template(@<text>                    
            <input name="checkedRecords" type="checkbox" value="@item.InstrumentId" title="checkedRecords"                         
                @if (Model.SelectedInstrumentIds.Contains(item.InstrumentId))
    {                            
                    <text>checked="checked"</text>                        
    }                    
                />                
            </text>).Title("").Width(36).HtmlAttributes(new { style = "text-align:center" });
  
            columns.Bound(model => model.InstrumentId).Title("Id");
            columns.Bound(model => model.TagName).Title("Tag Name");
            columns.Bound(model => model.TagDescription).Title("Tag Description");
            columns.Bound(model => model.EngUnits).Title("End Units");
        }).Sortable().Filterable()) 
  
       <p>    
       <button type="submit" class="t-button t-state-default">Display checked orders</button>
       </p>
    }

2 Answers, 1 is accepted

Sort by
0
superservo15
Top achievements
Rank 1
answered on 13 Feb 2013, 03:59 PM
If anyone cares or stumbles upon this, I just used jquery to get a comma seperated string

var StateIDs = $(':checked').map(function () { return $(this).val(); }).get().join(',');

Now I'm wondering, does anyone know to to return my string to the calling parent?

 

0
Daniel
Telerik team
answered on 15 Feb 2013, 03:27 PM
Hello,

I am not sure if I understand exactly the needed functionality. If you wish to post the form from the Window to a different action then you should specify this through to the BeginForm method:

Html.BeginForm("Action", "Controller");
The modelbinder should automatically populate the array with the values from the checked records.
If you have another form in the "calling parent" that you wish to submit the values then I can suggest to set the string with the found IDs to a hidden input and then split the string on the server. Kind regards,
Daniel
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
Tags
General Discussions
Asked by
superservo15
Top achievements
Rank 1
Answers by
superservo15
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or