これが本当の質問なのか、それともやり方が間違っているのかわかりませんが、JSON オブジェクト (ノックアウトから) を MVC コントローラーへのフォーム送信と一緒に投稿するにはどうすればよいですか?
まず、これは私のコントローラーです:
[HttpPost]
public ActionResult CreateLoanApp(PeopleViewModel MyViewModel)
{
//Do something on MyViewModel;
return RedirectToAction("Index");
}
[HttpPost]
public JsonResult CreateLoanApp(string deductions)
{
//Do something on string deductions;
}
そして、これは私の見解です:
<h2>My Form </h2>
@using (Html.BeginForm(new { @class = "submitForm" }))
{
<label>Loan Amount</label>
@Html.DropDownListFor(model => model.Loan.LoanAmount, Model.DropDownOfLoanAmount, new { @class = "LoanAmount", @data_bind = "value: selectedLoanAmount" })
@Html.ValidationMessageFor(model => model.Loan.LoanAmount)
<label>Loan Receivable</label>
@Html.TextBoxFor(model => model.Loan.LoanReceivable, "{0:0,0.00}", new { @class = "LoanReceivable", @readonly = true, dir = "rtl", @data_bind = "value: loanReceivable" })
@Html.ValidationMessageFor(model => model.Loan.LoanReceivable)
<label>Interest</label>
@Html.TextBoxFor(model => model.Loan.Interest, "{0:0,0.00}", new { @readonly = true, @class = "Interest", dir = "rtl", @data_bind = "value: interest" })
<table class="input-group">
<tbody data-bind="foreach: loanDeductions">
<tr>
<td><strong data-bind='text: deductionName'></strong></td>
<td>
<input class="deductionCode form-control" data-bind='value: amount, valueUpdate: "afterkeydown"' /></td>
<td><a href='#' data-bind='click: $parent.removeLine'>Delete</a></td>
</tr>
</tbody>
</table>
<button type="button" class="btn btn-danger" data-bind="click: save">Save Deduction</button>
<button type="submit" class="btn btn-primary">Save changes</button>
}
ご覧のとおり、2 つの異なる保存ボタン
があります。
2.一方、「変更を保存」ボタンは、フォームをコントローラーに送信し、「MyViewModel」を渡す送信ボタンです。
今私がやろうとしているのは、2 つのボタンを 1 つに結合し、2 つのオブジェクトを 1 つのコントローラーに一緒に渡すことです。
つまり、次のような 2 つのパラメーターを受け入れるアクションを作成したいということです。
[HttpPost]
public ActionResult CreateLoanApp(PeopleViewModel MyViewModel, string deductions)
{
// Do something on MyViewModel
//Do something on string deductions;
}
これは可能ですか。可能であれば、その方法を教えていただけますか。
どんな助けでも大歓迎です。詳細が必要な場合は、コメントしてください。ありがとう!