ASP.NET: MVC 4 Razor View Get Confirm Message Before Delete | Coding Cluster - using asp.net, c#, mvc 4, iphone, php, ios, javascript, in asp.net mvc 3 & more
 

ASP.NET: MVC 4 Razor View Get Confirm Message Before Delete

Wednesday

ASP.NET MVC 4: Confirmation alert before delete:
This is the sample code for display a confirmation alert message before  delete an employe detail.
                                               
                                     
In View:

@Html.ActionLink("Delete", "DeleteEmp", new { id = item.Id }, new { onclick = " return DeleteConfirm()" })
In Script:

function DeleteConfirm(){
        if (confirm("Are you sure want to delete record"))
            return true;
        else
            return false;     
    }
In Controller:

   public ActionResult DeleteEmp(int id)
   { 
            var empDelete = (from emp in dbml.M_Employees  where emp.Id == id   select emp).Single(); 
            dbml.M_Employees.DeleteOnSubmit(empDelete); 
            dbml.SubmitChanges(); 
            return RedirectToAction("Index"); 
   }

6 comments:

Goutham said...

Nice and thanks :)

Alex Barberi said...

Excellent! Thank you very much!

MVC is awesome!

Anonymous said...

thanks- pretty useful

Anonymous said...

It works with actionlink, but how can it work with button?

Unknown said...

its works

Thanks

Anonymous said...

Nice, clear information. Thank you.

Post a Comment

Share your thoughts here...

 
 
 

RECENT POSTS

Boost

 
Blogger Widgets