我有以下 jQuery 我正在尝试将一些数据(使用getSubscribeFormData
)发布到 Razor(chtml)函数,但是当我从 Razor 函数执行 Request["email"] 时,我得到空值。如何将数据发布到 Razor 功能。提前致谢
我的jQuery如下:
/* ---------------------------------------------------------------------- */
/* Newsletter Subscription
/* ---------------------------------------------------------------------- */
if ($().validate) {
$("#send-newsletter-form").validate();
}
var newsletterForm = $("#newsletter-form");
if (newsletterForm && newsletterForm.length > 0) {
var newsletterSubscribeButton = newsletterForm.find("#subscribe");
var newsletterEmailInput = newsletterForm.find("#newsletter");
newsletterSubscribeButton.bind("click", function () {
if ($("#newsletter-form").valid()) {
$("#subscribe").attr('disabled', 'disabled');
jQuery.ajax({
type:"POST",
url:\MacroScripts\Email.cshtml",
data:getSubscribeFormData(),
statusCode:{
200:function () {
$("#newsletter-notification-box-success").css('display', '');
newsletterSubscribeButton.removeAttr('disabled', '');
resetSubscribeFormData();
},
500:function () {
$("#newsletter-notification-box-error").css('display', '');
newsletterSubscribeButton.removeAttr('disabled');
}
}
});
}
function getSubscribeFormData() {
var data = 'action=subscribe';
if (newsletterEmailInput && newsletterEmailInput.length > 0) {
data += '&email=' + newsletterEmailInput.attr('value');
}
return data;
}
function resetSubscribeFormData() {
if (newsletterEmailInput && newsletterEmailInput.length > 0) {
newsletterEmailInput.attr('value', '');
}
}
return false;
});
}
我在 \MacroScripts\Email.cshtm 的 Razor 脚本如下所示
@using System.Web.Mvc
@{
var action = Request["action"] ;// i get null
var email = Request["email"] ;// i get null
}