Asp.net core 我是否使用了HttpGet和HttpPost错误?ASP.NETC
代码: 但我了解到,HttpGet只支持获取数据而不做其他事情,而[HttpGet]DeleteProduct并没有这样做。事实上,如果我将DeleteProduct更改为[HttpPost],ID将为0,那么如何在视图中获取ID 在第页上设置产品时: 当我在显示所有详细信息的页面上时,我必须单击删除: 您缺少产品id作为HttpPost传递的输入 ...Asp.net core 我是否使用了HttpGet和HttpPost错误?ASP.NETC,asp.net-core,model-view-controller,http-get,Asp.net Core,Model View Controller,Http Get,代码: 但我了解到,HttpGet只支持获取数据而不做其他事情,而[HttpGet]DeleteProduct并没有这样做。事实上,如果我将DeleteProduct更改为[HttpPost],ID将为0,那么如何在视图中获取ID 在第页上设置产品时: 当我在显示所有详细信息的页面上时,我必须单击删除: 您缺少产品id作为HttpPost传递的输入 ... 1.奇怪的是,您用HttpPost注释了第一个DeleteProduct操作方法,用HttpGet注释了第二个DeleteProduct方
1.奇怪的是,您用HttpPost注释了第一个DeleteProduct操作方法,用HttpGet注释了第二个DeleteProduct方法。依我看,第一个应该是HttpGet,第二个应该是HttpPost。2.另外,请将您的截图图像替换为代码文本。否则,很可能有人会投反对票。@我知道这更有意义,但当我将第二次删除更改为HttpPost时,我没有得到ProductID,我只得到0。还有,为什么你要在delete或get中发布数据,而不是id,又名Name=Name,Price=Price,Photo=Photo,Likes=Likes,描述=描述,类别=类别可能不需要
[HttpPost]
public ActionResult DeleteProduct(int ProductID, string Name, decimal Price, string Photo, int Likes, string Description, Enums.ProductCategory.Category Category)
{
ProductModel productModel = new ProductModel
{
ProductID = ProductID,
Name = Name,
Price = Price,
Photo = Photo,
Likes = Likes,
Description = Description,
Category = Category
};
return View(productModel);
}
[HttpGet]
public ActionResult DeleteProduct(int ProductID)
{
if(UserController.userSessionID != 0)
{
user.DeleteProduct(ProductID);
return RedirectToAction("ViewSellerProducts", "Product");
}
return View();
}