2017-11-27 11 views
0

linenumberという変数を使用して、項目数に関連した行数を取得しています。しかし、行番号は0を返し続けます。私はデータベースから項目のリストを引っ張っていますので、そうでなければ私はそうしません。私の質問は、編集を完了させる別の方法です。Asp.net MVCで正しく編集する方法

ビュー

@Html.HiddenFor(model => model.item.lineNum) 
</div> 
<br /><br /> 
<h4>Issued Items</h4> 
    <hr /> 
    <div class="form-group"> 
     <table> 
     <tr> 
      <th class="col-md-4">Item Number</th> 
      <th class="col-md-4">Item Description</th> 
      <th class="col-md-4">Expense Account</th> 
      <th class="col-md-2">Quantity Requested</th> 
      <th class="col-md-2">Quantity Issued</th> 
      <th class="col-md-1">UOM</th> 
      <th class="col-md-1">Item Price</th> 
     </tr> 
     @{ 
      foreach (var issueditem in ViewBag.IssuedItems) 
      { 
      <tr> 
       <td class="col-md-4">@issueditem.itemNumber</td> 
       <td class="col-md-4">@issueditem.description</td> 
       <td class="col-md-4">@issueditem.expense_account.getDescription</td> 
       <td class="col-md-2">@issueditem.quantity.ToString()</td> 
       <td class="col-md-2">@issueditem.quantityI.ToString()</td> 
       <td class="col-md-1">@issueditem.selecteduomtext </td> 
       <td class="col-md-1">@issueditem.price.ToString()</td> 
       <td>@Html.ActionLink("Edit", "Edit", new { id = issueditem.lineNum })</td> 
      </tr> 
      } 
     } 
     <tr></tr> 
     </table> 

コントローラ

public ActionResult Edit(int id) 
{ 
    getIssue.item = getIssue.items[id - 1];//Returns the requested item for editing 
    return View(getIssue); 
} 


    /// <summary> 
    /// Gets the changes submitted from the user and updates the Item in the List 

    [HttpPost] 
    public ActionResult Edit(Issue issue) 
    { 
    int indx = issue.item.lineNum - 1; 
    getIssue.items[indx] = issue.item; 
    //return View(getIssue); 
    return RedirectToAction("IssueItem", "Issue", new { id = indx }); 
    } 

答えて

0

は、単にissuedItem.idを使用し、これは

<td>@Html.ActionLink("Edit", "Edit", new { id = issueditem.id})</td> 
0123使用して、すべてのレコード

のためにあなたのIDを与えます

+0

が、idはidは離れてクラス –

+0

に含まれていません。私はボタンを使用していません –

0

私はあなたがこの作業にAjaxを使用できると思います。

function edit(id) { 
    $.ajax({ 
     url: "Controller/Method", 
     type: "POST", 
     data: {"id": your id}, 
     success: function(data) { 
     //redirect anywhere you want if success 
     }, error: function (data) { 
     //do what you want if error 
     } 
    }); 
} 

<td><input type="button" onclick="edit(this)" /></td> 
+0

のではなく、ビューが同じままだろうというとき、私はすべてのレコードのIDを取得する必要があります正確にどのようにモデルクラス –

+0

あなたの​​要素の中であなたが望む要素を編集することができます。 –

+0

コントローラーに関しては同じままです –

関連する問題