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 つのチェックボックス (Priority と Return Receipt) の値を JQuery 関数に渡すことです。EditorFor 私が最近発見したように (難しい方法)、セット ID の受け入れに問題があります
。解決策はありますか? 前もって感謝します !

これらの値をコントローラーメソッド「SaveNewMail」と呼ばれるAjaxに渡すにはどうすればよいですか

4

1 に答える 1

0

SaveMail 関数 (コントローラー) で 2 つのチェックボックスの値が必要な場合は、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 に答える