Asp.net mvc Can';在Ajax调用中序列化Telerik MVC控件

Asp.net mvc Can';在Ajax调用中序列化Telerik MVC控件,asp.net-mvc,ajax,telerik-mvc,Asp.net Mvc,Ajax,Telerik Mvc,我在通过Ajax调用将模型从视图传递到控制器时遇到问题。具有Telerik html“For”控件的所有模型属性都不会保留在模型中。我可以访问控制器中这些值的唯一方法是使用请求[“control_name”]。所有其他标准控件(如input type=text)都可以很好地序列化。我做错了什么 以下是我的ajax调用: function ImportLogFile() { $.ajax({ url: '/Job/ImportLogFile', type:

我在通过Ajax调用将模型从视图传递到控制器时遇到问题。具有Telerik html“For”控件的所有模型属性都不会保留在模型中。我可以访问控制器中这些值的唯一方法是使用请求[“control_name”]。所有其他标准控件(如input type=text)都可以很好地序列化。我做错了什么

以下是我的ajax调用:

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) + "...");
        }
    });
}
控制器:

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

@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>
@model viaguage.Jams.Data.tbljobstask
@使用(Html.BeginForm())
{
CAT刀具类型:
@{Html.Telerik().ComboBoxFor(model=>model.CatToolID)
.Name(“作业任务\u CatToolID”)
.BindTo(新选择列表((IEnumerable)视图数据[“CatTools”],“CatToolID”,“Description”))
.HtmlAttributes(新的{style=“width:220px;”});
}
}
我认为
.Name(“jobstask\u CatToolID”)
是问题的根源。当您将combobox的Name属性更改为property Name以外的其他属性时,modelbinder不会自动将其绑定到属性。ModelBinder只查看发布的键,然后在模型中搜索匹配的属性并相应地填充它们。当binder找到key
jobstask\u CatToolID
时,它可能在模型中找不到匹配的属性,因此它没有分配给任何属性。您可以通过省略
Name(-)
方法来检查这一点,然后将数据发布到控制器