我是MVC
的新用戶。如何在MVC的單個視圖中添加編輯,刪除和搜索功能?
在MSDN上我研究過,應該有文件夾view
與controller
同名。對於controller
中的每個Action Method
,我們必須在同一個文件夾中創建一個View
。
我創建其中一個測試應用程序:
我有一個homeController
與Index ActionMethod
。相應的,我有一個View
View/home/Index
,它只顯示僱員的名單。
我知道我可以在homeController
中添加[HTTP POST] Index ActionMethod
。
但我想在視圖上添加Delete
和Search
功能。因此,用戶可以搜索那裏有姓名的員工,並可以刪除同一頁面上的員工。
我不知道如何才能繼續使用此功能。
我仍然使用這段代碼。
homeController
public ActionResult Index()
{
ViewBag.text = "Records Listing";
var q = from p in objEmp.tbemployees select p;
return View(q);
}
Index.cshtml
@model IEnumerable<MvcApplication6.Models.tbemployee>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h1>@ViewBag.text</h1>
<table style="font-size:15px;">
<tr>
<th>
Name
</th>
<th>
Address
</th>
<th>
Sallary
</th>
</tr>
@foreach (var item in Model)
{
<tr >
<td style="padding:7px;">
@Html.DisplayFor(mm => item.ename)
</td>
<td style="padding:7px;">
@Html.DisplayFor(mm => item.eadd)
</td>
<td style="padding:7px;">
@Html.DisplayFor(mm => item.esal)
</td>
<td style="padding:7px; color:Blue; text-decoration:underline;">
@Html.ActionLink("Edit", "Edit", new { id = item.empno })
</td>
</tr>
}
</table>
感謝。
什麼? – 2013-04-22 06:42:56