2017-06-17 19 views
-1

私の編集フォームからいくつかの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> 

ありがとうございます!

+1

JavaScriptの 'Update()'メソッドは何ですか?そして、なぜあなたはモデルの元の値を渡していますか?なぜあなたはフォームを提出するだけではないのですか?また、POSTメソッドを表示する必要があります。 –

+0

@StephenMuecke異なるフォームの3つのボタン、つまりステータスを増やすためのボタンと、ステータスを減らすための2つ目のボタンと、ホールテーブルを更新するための1つのボタンがありますので、お返事ありがとうございます。私が求めているそれらの価値を得るために? –

+0

ビューに3つのボタンが表示されていません。そしてあなたの質問にそのどれも説明されていません。そしてあなたは私の質問のどれにも反応していません。誰もこれに答えることはできません。 –

答えて

0

<input type="submit" value="Save" class="btn btn-default" onclick="return Update(@Model.ProductId,@Model.CountryId,@Model.ModelId)/>あなたは3つの値をすべて取得します。ハッピーコーディング!

+0

パーフェクト、それは働いています。私はあなたに感謝する方法がありません!あなたはちょうど奇妙な質問なしで私を得た。いくつかのpoepleは答えたミルンの質問を生成します。 –

関連する問題