我有以下jQuery我试图将一些数据(使用getSubscribeFormData
)发布到Razor(chtml)函数但是当我从Razor函数执行Request [“email”]时,我得到null。如何将数据发布到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;
});
}
我的Razor脚本位于\ MacroScripts \ Email.cshtm,如下所示
@using System.Web.Mvc
@{
var action = Request["action"] ;// i get null
var email = Request["email"] ;// i get null
}