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

Can't serialize Telerik controls in Ajax call

1 Answer 31 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.
Kevin
Top achievements
Rank 1
Kevin asked on 07 Sep 2011, 03:11 AM
I am having problems passing my model from my view via an Ajax call to my controller.  All of the model properties that have Telerik html 'For' controls in the view do not persist in the model.  The only way I can access those values in the controller is using Request["control_name"].  All other standard controls like input type=text serialize just fine.  What am I doing wrong?  Here is my ajax call:

function ImportLogFile() {
 
    $.ajax({
        url: '/Job/ImportLogFile',
        type: 'POST',
        data: $("form").serialize(),
        success: function (data)
        {
            $('body').css('cursor', 'auto');
            alert("Word Counts imported.");
        },
        error: function (xhr, status, error) {
            alert(status + ": " + strip(xhr.responseText).substring(0, 1000) + "...");
        }
    });
}


Controller:
[HttpPost]
public ActionResult ImportLogFile(tblJobTask model)
{
    ...
}

View:
@model viaLanguage.Jams.Data.tblJobTask
 
<html>
<head></head>
<body>
     
@using (Html.BeginForm())
{
 
    <label class="editorLabel">CAT Tool Type:</label>
        @{ Html.Telerik().ComboBoxFor(model => model.CatToolID)
                .Name("JobTask_CatToolID")
                .BindTo(new SelectList((IEnumerable)ViewData["CatTools"], "CatToolID", "Description"))
                .HtmlAttributes(new { style = "width:220px;" });
         }
  
<input id="btnImport" type="button" onclick="ImportLogFile();"  />
     
}
     
</body>
</html>

Steve




1 Answer, 1 is accepted

Sort by
0
Accepted
John DeVight
Top achievements
Rank 1
answered on 07 Sep 2011, 05:05 AM
Hi Steve,

Based on the code you provided, I put together a working sample project.  (See attached AjaxSerialize.zip)  The only change that I made to your code is the name of the ComboBox.  I changed it to "CatToolID".  The reason for this, is that the "CatToolID" property is found in the "tblJobTask" model.


If the tblJobTask model had a property called "JobTask", then you would want to name the ComboBox "JobTask_CatToolID".  For example:

public class tblJobTask
{
    public JobTask JobTask { get; set; }
}

public class JobTask
{
    public int CatToolID { get; set; }
}

Let me know how this works out for you =)

Regards,

John DeVight
Tags
General Discussions
Asked by
Kevin
Top achievements
Rank 1
Answers by
John DeVight
Top achievements
Rank 1
Share this question
or