动作方法返回null

问题描述 投票:0回答:1

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

tsql model-view-controller
1个回答
0
投票

看来您的ActionLink设置不正确。更改此

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

为此

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

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

© www.soinside.com 2019 - 2024. All rights reserved.