点网MVC中的“ RedirectToAction”方法如何工作?

时间:2019-07-06 02:23:08

标签: .net .net-core dotnet-httpclient redirecttoaction

public ActionResult UpdateProduct(ProductViewModel viewModel){return RedirectToAction("Index","Product");
}

此处“ ProductViewModel”是类名,“索引”是视图页` 以及“产品”控制器。

现在我的问题是RedirectToAction方法的流程如何,当我单击UpdateProduct时它将如何工作。

public ActionResult UpdateProduct(ProductViewModel viewModel)
        {
            var oldProduct = _context.products.Single(r=>r.Id==viewModel.Id);

            oldProduct.Id = viewModel.Id;
            oldProduct.Name = viewModel.Name;
            oldProduct.Color = viewModel.Color;
            oldProduct.Description = viewModel.Description;
            oldProduct.Fabric = viewModel.Fabric;
            oldProduct.Quantity = viewModel.Quantity;
            oldProduct.UnitPrice = viewModel.UnitPrice;
            oldProduct.CategoryId = viewModel.CategoryId;
            _context.SaveChanges();
           return RedirectToAction("Index", "Product"); }

0 个答案:

没有答案