سؤال

I have the following view:

<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>

And the controller looks like:

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

However, when I click on Edit Line or Delete Line the value is not passed to controller action. It is always Null.

Can anyone please point me to the issue? Any comments will be appreciated.

هل كانت مفيدة؟

المحلول

I found what the problem was:

Parameter name should be same in the Action Link and the Controller Parameter.

eg .id should be .hireLineId to match the controller parameter name!!

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top