0

私は次の見解を持っています:

<h2>
Contract</h2>
@Using Html.BeginForm()
@Html.ValidationSummary(False)
@<fieldset>
<legend>Hire Contract</legend>
<div class="editor-label">
@Html.LabelFor(Function(model) model.ContractNo)
</div>
<div class="editor-field">
@Html.DisplayTextFor(Function(model) model.ContractNo)
</div>

<div class="editor-label">
@Html.LabelFor(Function(model) model.HireId)
</div>
<div class="editor-field">
@Html.DisplayTextFor(Function(model) model.HireId)
</div>

-- More fields here --- 

<div>
<table>
<tr>
<th>
Line Id
</th>
<th>
Description
</th>
<th>
Return Quantity
</th>
<th>
</th>
</tr>

<p/>
@Html.ActionLink("Add Line", "AddContractLine")
<p/>

@For Each item In Model.HireContractLines
Dim currentItem = item
@<tr>
<td>
@Html.DisplayFor(Function(modelItem) currentItem.LineId)
</td>
<td>
@Html.DisplayFor(Function(modelItem) currentItem.Description)
</td>

-- Many other fields here ...

<td>
@Html.ActionLink("Edit", "EditContractLine", New With {.id = currentItem.LineId})
|
@Html.ActionLink("Delete", "DeleteContractLine", New With {.id = currentItem.LineId})
|
@Html.ActionLink("Return Line", "ReturnContractLine", New With {.id = currentItem.LineId})
</td>
</tr>
Next
</table>
</div>
<p>
<input type="submit" value="Full Return" />
</p>
</fieldset>

そして、コントローラーは次のようになります。

Function EditContractLine(hireLineId? As Integer) As ActionResult
Dim contractLine = GetContractLine(CInt(hireLineId))
Return View(ContractLine)
End Function

ただし、[行の編集]または[行の削除]をクリックすると、値がコントローラーアクションに渡されません。常にNullです。

誰かが私に問題を指摘してもらえますか?コメントをいただければ幸いです。

4

1 に答える 1

0

私は問題が何であるかを見つけました:

パラメータ名は、アクションリンクとコントローラパラメータで同じである必要があります。

たとえば、コントローラーのパラメーター名と一致させるには、.idを.hireLineIdにする必要があります。

@ Html.ActionLink( "Return Line"、 "ReturnContractLine"、New With {.id = currentItem.LineId})

于 2012-08-04T00:50:53.440 に答える