1

次の内容を含むビューがあります。

(...)

<div id="txtMan@(item.ManufacturerId)" hidden>
    @Html.TextBoxFor(modelItem => item.ManufacturerName, new { @id = "txtBoxMan"+item.ManufacturerId })
</div>
<td>
    <input class="btnSave" id="btnSave@(item.ManufacturerId)" type="button" value="Save" onclick="saveButtonPressed(@item.ManufacturerId);" hidden />
</td>

(...)

対応するJavaScript:

saveButtonPressed = function (id) {
    var newManName = $('#txtMan' + id).val();

    $.ajax({
        type: "POST",
        async: true,
        url: '/Admin/BrandConfigurationNameUpdate/' + newManName,
        dataType: "json",
        success: function () {
            alert('Added');
        }
    });
}

そしてコントローラー:

public static void BrandConfigurationNameUpdate(string id)
{ 

}

私の目的は、テキストボックスの値をデータベースに保存することです。ただし、コントローラーにブレークポイントを設定しましたが、ブレークポイントに到達しません。なにか提案を?

編集:GetJSONを試しましたが、まだ機能していません。コードは次のとおりです。

saveButtonPressed = function (id) {
    var newManName = $('#txtBoxMan' + id).val();
    alert(newManName);
    var URL = "~/Areas/Admin/Controller/Admin/BrandConfigurationNameUpdate/";

    $.getJSON(URL, { "id": id, "newManName": newManName }, function (data) {
        alert("finished");
    });
}
4

1 に答える 1

3

オプションをオブジェクト(キーと値のペア)として渡す必要がありdataます。そうしないと、値がPOSTされません。

saveButtonPressed = function (id) {
    var newManName = $('#txtMan' + id).val();

    $.ajax({
        type: "POST",
        async: true,
        url: '/AdminController/BrandConfigurationNameUpdate/',
        data : {newManName : newManName},
        dataType: "json",
        success: function () {
            alert('Added');
        }
    });
}
于 2013-03-19T18:02:03.000 に答える