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

[Solved] Returning Checked Rows with Ajax

2 Answers 111 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.
Radu
Top achievements
Rank 1
Radu asked on 03 Jul 2011, 08:30 PM
Hi,

I have a Chckbox grid in a PartielView. The PartialView is displayed in a TabStrip which is embedded in a Grid. Everything is in Ajax mode and displays just fine, but when I post the array of checked values to my controller, it comes up null. Can someone please give me some help.

The PartialView :

<script type="text/javascript">
    displayChecked = function (taskId) {
        var $checkedRecords = $(':checked');        
        if ($checkedRecords.length < 1) {
            alert('Check a few grid rows first.');
            return false;
        } else {
            $.ajax({
                type: "POST",
                url: '/Tasks/DisplayChecked/',
                contentType: 'application/json; charset=utf-8',
                data: JSON.stringify({ checkedRecords: $checkedRecords , Id: taskId }),     
                dataType: 'json'
            })
            .success(function (result) {
                alert('Success');
            })
            .error(function (result) {
                alert('Failed');
            });
  
            return false;
        }
    }   
 </script>
  
<div style="width:400px">
    <% =Html.Telerik().Grid<TTManager.Models.Employee>()
            .Name("Employees_" + ViewData["TaskId"].ToString())
            .Columns(columns =>
            {
                columns.Bound(o => o.UserName)
                    .ClientTemplate("<input type='checkbox' name='checkedRecords' value='<#= UserName #>' />")
                    .Title("")
                    .Width(36)
                    .HtmlAttributes(new { style = "text-align:center" });
                columns.Bound(o => o.Name);
            })
            .DataBinding(dataBinding =>
            {
                dataBinding.Ajax()
                    .Select("_GetTaskEmployees", "Tasks");
            })
            .Scrollable()
            .Footer(false)
            .ToHtmlString()
    %>    
</div>

The controller:

public JsonResult DisplayChecked( string[] checkedRecords, int Id) 
{
    // checkedRecords is null, taskId is good.
    return Json("TaskEmployees");
}

Any help is greatly appreciated.

2 Answers, 1 is accepted

Sort by
0
Radu
Top achievements
Rank 1
answered on 07 Jul 2011, 04:22 AM
Anybody on this?
0
Atanas Korchev
Telerik team
answered on 07 Jul 2011, 07:20 AM
Hi Radu,

 I don't think this is related in any way to Telerik Extensions for ASP.NET MVC. 
 
 ASP.NET MVC action methods do not work by default when you post data in JSON format to them. Check this blog post.

Regards,
Atanas Korchev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Grid
Asked by
Radu
Top achievements
Rank 1
Answers by
Radu
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or