在VendorControllder
中,我有两种方法(一种显示全部,一种删除供应商)
// to display all vendor
public ActionResult Index()
{
SLMEntitiesDB dbContext = new SLMEntitiesDB();
List<Vendor> Vlist = dbContext.Vendors.ToList();
return View(Vlist);
}
// to delete vendor
public ActionResult delv(Vendor VID) //this return null
{
SLMEntitiesDB dbContext = new SLMEntitiesDB();
dbContext.DelV(VID.VID);
return RedirectToAction("Index");
}
DelV
是如下过程
create procedure [dbo].[DelV]
(@VID int)
as
begin
Delete from vendor where VID=@VID
end
来自供应商索引,我有两个HTML Action链接,如下所示
@Html.ActionLink("Delete", "delv", new { VID = item.VID },null)
当我运行应用程序时,VID
返回null
看来您的ActionLink设置不正确。更改此
@Html.ActionLink("Delete", "delv", new { VID = item.VID },null)
为此
@Html.ActionLink("Delete", "delv", "Vendor", new { VID = item.VID },null)
记住对Html.ActionLink的设置是:链接文本,操作名称,控制器名称,路由值,HTML值