次の内容を含むビューがあります。
(...)
<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");
});
}