I have an input form (only one field, Serial Number) a Button to submit the form and a list to show all the Serial Numbers:
The way it works is, I inform a serial number and click 'Add to List' and the controller will add that Serial Number to the list and return to Index.
Here is my controller:
[HttpPost]
public ActionResult Create(Product productFromView)
{
try
{
Product product = new Product();
product.Id = StaticProducts.Products.Count + 1;
product.SerialNumber = productFromView.SerialNumber;
//check if serial number has been added to the list already
if (Products.Any(s => s.SerialNumber == product.SerialNumber))
{
//serial number has been added to the list already
//return to the view with a pop up message asking if the user wants to insert that serialnumber anyway
//if user replies 'yes': add serial number to the list
//if user replies 'no': return to index view
}
else
{
Products.Add(product);
}
return RedirectToAction(nameof(Index));
}
catch
{
return View(productFromView);
}
}
Now I want to check if the serial number has been added to the list, if so, show a message to the user asking if he wants to insert the serial number again. And only if user replies 'yes' we add the serial number to the list.
I've already tried a few different things, but I still couldn't find out a proper way of doing that, I believe I will have to use JavaScript, but I still can't figure out how am I supposed to do that, like, what do I do in the controller to return to the view with a pop-up message, and if the user replies yes how can I return to the controller to add the serial number to the list.
Thanks