【发布时间】:2011-09-07 12:36:04
【问题描述】:
我在通过 Ajax 调用将模型从我的视图传递到我的控制器时遇到问题。具有 Telerik html 'For' 控件的所有模型属性都不会保留在模型中。我可以在控制器中访问这些值的唯一方法是使用 Request["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>
【问题讨论】:
标签: asp.net-mvc ajax telerik-mvc