私の編集フォームからいくつかのIDの値を渡したいと思います。ASP.Net MvcでEditorForの値を取得し、パラメータとしてボタンに値を渡す方法
<input type="submit" value="Save" class="btn btn-default" onclick="return Update(@(model.ProductId),@(model.CountryId),@(model.ModelId))/>
でもない作業: みましょう、私はのProductId、CountryIdとModelIdの値を渡したいと私は、このようにしようとしたと言います。 私の編集フォームにあります。これは私のフォームです。
@model Products.Models.Product
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Product</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.ProductId)
@Html.HiddenFor(model => model.CountryId)
@Html.HiddenFor(model => model.ModelId)
<div class="form-group">
@Html.LabelFor(model => model.ProductName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ProductName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Model, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Model, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Model, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Model, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Status, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Status, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Status, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" onclick="return Update(@(model.ProductId),@(model.CountryId),@(model.ModelId))/>
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
ありがとうございます!
JavaScriptの 'Update()'メソッドは何ですか?そして、なぜあなたはモデルの元の値を渡していますか?なぜあなたはフォームを提出するだけではないのですか?また、POSTメソッドを表示する必要があります。 –
@StephenMuecke異なるフォームの3つのボタン、つまりステータスを増やすためのボタンと、ステータスを減らすための2つ目のボタンと、ホールテーブルを更新するための1つのボタンがありますので、お返事ありがとうございます。私が求めているそれらの価値を得るために? –
ビューに3つのボタンが表示されていません。そしてあなたの質問にそのどれも説明されていません。そしてあなたは私の質問のどれにも反応していません。誰もこれに答えることはできません。 –