2012-09-09 94 views
0

點擊刪除鏈接(這是一個按鈕)沒有任何反應。我的意思是不張貼形式。不知道爲什麼它發生。提交按鈕不會發布頁面

@foreach (var item in Model) { 
<tr> 
    <td> 
     @Html.DisplayFor(modelItem => item.RegistrationNo) 
    </td> 
    <td> 
     @Html.DisplayFor(modelItem => item.FirstName) 
    </td> 
    <td> 
     @Html.DisplayFor(modelItem => item.MiddleName) 
    </td> 
    <td> 
     @Html.DisplayFor(modelItem => item.LastName) 
    </td> 
    <td> 
     @Html.DisplayFor(modelItem => item.DateofBirth) 
    </td> 
    <td> 
     @Html.ActionLink("Edit", "Edit", new { id=item.Id }) | 
     @Html.ActionLink("Details", "Details", new { id=item.Id }) | 
     <input type="submit" value="Delete" name="Delete" style="border: none; background: none; 
      text-decoration: underline; cursor: pointer;"> 
    </td> 
</tr> 
+0

你能還包括形式,例如@ Html.BeginForm(Action,Controller)? – StuartLC

+1

我沒有看到'form'標籤,如果它發佈了,DisplayFor也不會在服務器端給你任何東西,你需要爲每個顯示都有'HiddenFor',以便將值發佈回服務器 – Rafay

回答

1

這裏是你可以嘗試什麼

@using (Html.BeginForm()) { 
<table> 

@foreach (var item in Model) { 
<tr> 
    <td> 
     @Html.DisplayFor(modelItem => item.RegistrationNo) 
     @Html.HiddenFor(modelItem => item.RegistrationNo) 
    </td> 
    <td> 
     @Html.DisplayFor(modelItem => item.FirstName) 
     @Html.HiddenFor(modelItem => item.FirstName) 
    </td> 
    <td> 
     @Html.DisplayFor(modelItem => item.MiddleName) 
     @Html.HiddenFor(modelItem => item.MiddleName) 
    </td> 
    <td> 
     @Html.DisplayFor(modelItem => item.LastName) 
     @Html.HiddenFor(modelItem => item.LastName) 
    </td> 
    <td> 
     @Html.DisplayFor(modelItem => item.DateofBirth) 
     @Html.HiddenFor(modelItem => item.DateofBirth) 
    </td> 
    <td> 
     @Html.ActionLink("Edit", "Edit", new { id=item.Id }) | 
     @Html.ActionLink("Details", "Details", new { id=item.Id }) | 
     <input type="submit" value="Delete" name="Delete" style="border: none; background: none; 
      text-decoration: underline; cursor: pointer;"> 
    </td> 
</tr> 


</table> 


}