Answer the question
In order to leave comments, you need to log in
How to pass data from view to method?
There is a Customer controller, it has the DeleteCustomer action method.
public class CustomerController : Controller
{
[HttpGet]
public IActionResult Index()
{
IEnumerable<CustomerViewModel> customers =
_customerRepository.GetAllCustomers().Select(s => new
CustomerViewModel
{
CustomerId = s.CustomerId,
Name = s.Name,
Adress = s.Adress
});
return View("Index", customers);
}
[HttpPost]
public IActionResult DeleteCustomer(int id)
{
_customerRepository.Delete(id);
return LocalRedirect("~/Customer/Index");
}
}
<a asp-action="DeleteCustomer" asp-route-id="@item.CustomerId">Delete</a>
Answer the question
In order to leave comments, you need to log in
the method waits for a post request, and you make a get request with a link
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question