操作方法返回 null



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 操作链接,如下所示

@Html.ActionLink("Delete", "delv", new { VID = item.VID },null)

当我运行应用程序时,VID返回 null

看来您的操作链接设置不正确。 更改此内容

@Html.ActionLink("Delete", "delv", new { VID = item.VID },null)

对此

@Html.ActionLink("Delete", "delv", "Vendor", new { VID = item.VID },null)

请记住,Html.ActionLink 的设置是:链接文本、操作名称、控制器名称、路由值、HTML 值

最新更新