user7646784
user7646784

Reputation:

Confirmation dilog box in asp.net mvc5

public ActionResult Delete(int id)
{
        using (RegMVCEntities obj = new RegMVCEntities())
        {

            var employee = obj.tblRegistrations.Where(m => m.ID == id).FirstOrDefault();
            obj.tblRegistrations.Remove(employee);
            obj.SaveChanges();
            return RedirectToAction("Index");
        }                
} 

I want to display a confirmation dialog box so it should ask like "Do you want to delete the record" and when yes is clicked then it delete the record. i am not getting how to do it.

Upvotes: 0

Views: 69

Answers (2)

Dnomyar96
Dnomyar96

Reputation: 309

You can't show messages from a controller. That kind of thing has to be done from the view. So before you go to the action on the controller, you should show the confirmation dialog from the view first. If the user confirms you can go to the action, otherwise stay on the view (or alternitavly go to another action).

@Html.ActionLink("LinkText", "Action", "Controller", new { onclick = "return confirm('Message asking to confirm');"})

Upvotes: 0

शेखर
शेखर

Reputation: 17604

If you are using ActionLink MSDN LINK you can do as below

<%= Html.ActionLink(
    "Delete", 
    "Delete",
    new { onclick = return confirm('Are you sure you wish to delete ?');" }) 
%>

Upvotes: 1

Related Questions