0

我有以下jquery函数:

function SaveMail() {
    subject = $("#MailMsgSubject").val();
    message = $("#MailMsgMessage").val();
    to = To;
    cc = Cc;

    $.ajax({
        type: "POST",
        data: JSON.stringify({ subject: subject, message: message, listTo: to, listCc: cc }),
        url: '@Url.Action("SaveNewMail", "Mail")',
        contentType: "application/json; charset=utf-8",
        success: function (data) {
            $("#SuccesDiv").html("<b>Your message has been succesfully sent</b>");
        }
    });
}

我有以下观点:

<div style="float: left">
    Subject :
</div>
<div style="float: left; width: 30.5%">
    @Html.TextBoxFor(modelItem => Model.Subject, new { id = "MailMsgSubject", @style = "width:99%" })
</div>
<div style="clear: both" />

<div style="float: left">
    Priority :@Html.EditorFor(modelItem => Model.Priority, new { id = "MailMsgPriority" })
</div>
<div style="float: left">
    Return Receipt :@Html.EditorFor(modelItem => Model.ReturnReceipt, new { id = "MailMsgRR" })
</div>
<div style="float: left">
    Patient :@Html.TextBoxFor(modelItem => Model.Priority, new { id = "MailMsgPatient" })
</div>
<div style="clear: both" />

<div style="float: left">
    Message :
</div>
<div style="clear: both" />

<div style="float: left; width: 35%">
    @Html.TextBoxFor(modelItem => Model.Message, new { id = "MailMsgMessage", @style = "height: 220px; width:100%" })
</div>
<p style="text-align: right">
    <input type="button" id="btnSaveMailMessage" />
</p>

我的问题是将此处的 2 个复选框(优先级和回执)的值传递给我的 JQuery 函数。EditorFor 正如我最近发现的那样(艰难的方式)在接受一组 ID 时有问题 有
任何解决方案吗?提前致谢 !

如何将这些值传递给我的 Ajax,称为控制器方法“SaveNewMail”

4

1 回答 1

0

如果您需要 SaveMail 函数(控制器)中的两个复选框值,您可以通过重构 URL 在 Url.Action 中传递它们。

//read the checkboxvalues 
var yourPriorityCheckBoxValue = ?
var yourSendReceiptCheckBoxValue = ?

var urlAction = urlAction + '?priority=__VAR1__&returnReceipt=__VAR2__';
urlAction = urlAction.replace('__VAR1__',yourPriorityCheckBoxValue);
urlACtion = urlAction.replace('__VAR2__',yourSendReceiptCheckBoxValue);

现在,在您的控制器 SaveMail 函数中,读取查询字符串值。

希望这可以帮助。可能有比这更优雅的解决方案。

于 2012-04-19T09:06:29.073 回答