2012-08-02 82 views
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 

然而,當我點擊編輯線或刪除線該值不會傳遞給控制器​​操作。它總是空的。

任何人都可以請我指出這個問題?任何意見將不勝感激。

回答

0

我發現了什麼問題:

參數名稱應該是操作鏈接和控制器參數相同。

例如.id應該是.hireLineId以匹配控制器參數名稱!

@ Html.ActionLink(「Return Line」,「ReturnContractLine」,New with {.id = currentItem.LineId})

相關問題