【发布时间】:2012-02-29 19:45:34
【问题描述】:
即使我可以看到我在 http 标头中发布的值,控制器仍将这些值接收为 null,并且在查看完所有内容后我被难住了。
这是我的观点:
$("#dialog-form").dialog({
autoOpen: false,
height: 360,
width: 350,
modal: true,
buttons: {
"Send Message": function () {
if ($('#name').val() == '' || $('#email').val() == '' || $('#message').val() == '') {
$('.validation_message').html('required');
}
else {
var model =
{
Name: $('#name').val(),
Email: $('#email').val(),
Message: $('#message').val(),
ProfileEmail: $('#profile_email').val()
};
$.post('@Url.Action("SendMessage")', model, function (data) {
alert(data);
});
e.preventDefault();
$(this).dialog("close");
$('.validation_message').hide();
}
},
"Cancel": function () {
$(this).dialog("close");
$('.validation_message').hide();
}
}
});
$("#button-contact")
.button()
.click(function () {
$("#dialog-form").dialog("open");
});
我的控制器动作:
[HttpPost]
[ValidateInput(false)]
public ActionResult SendMessage(ProfileSendMessageModel message)
{
// some code here
return Content("Your message has been sent!");
}
模型始终显示为 null,但标头中的元素具有值。任何帮助将不胜感激!
【问题讨论】:
-
使用
HTML Form和serialize()创建javascript对象的状态。
标签: jquery asp.net-mvc-3 post dialog