@model IEnumerable<HelloWorldMvcApp.SampleViewModel>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap 101 Template</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
.field-validation-error {
<div class="col-md-6 col-md-offset-3">
<h1>Bootstrap Modal Popup Example</h1>
@using (Html.BeginForm())
@Html.ActionLink("Create New", "Create")
@Html.DisplayNameFor(model => model.Id)
@Html.DisplayNameFor(model => model.Name)
@Html.DisplayNameFor(model => model.Surname)
@foreach (var item in Model) {
@Html.DisplayFor(modelItem => item.Id)
@Html.DisplayFor(modelItem => item.Name)
@Html.DisplayFor(modelItem => item.Surname)
@Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
@Html.ActionLink("Delete", "Home", new { id=item.Id }, new { @class="element", @data_toggle = "modal", @data_target = "#exampleModalCenter", @data_name = item.Name, @data_id = item.Id })
@Html.Hidden("itemid", "", new { id = "itemid" })
@Html.Hidden("itemName", "", new { id = "itemname" })
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
<div id="modal-body" class="modal-body">
<h6>Are you sure that you want to delete this?</h6>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" id="Delete" class="btn btn-danger">Delete</button>
<div class="alert alert-warning fade">
<img src="http://entechprod.blob.core.windows.net/dotnetfiddle/morpheus.jpg" style="max-width:100%;"/><br/><br/>
<strong><span class="alert-content"></span></strong>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/mvc/4.0/jquery.validate.unobtrusive.min.js"></script>
<script type="text/javascript">
$('.element').click(function (e) {
var name = $(this).data('name');
$('#itemName').val(name);
$('#modal-body').html('Are you sure you want to delete: '+ name + '?');
$('#exampleModalCenter').modal('show');
console.log($(this).data('id'));
var id = $(this).data('id');
console.log($('#itemid').val());
$('#Delete').click(function () {
var id = $('#itemid').val();
$.post("@Url.Action("Delete", "Home")", { id: id }, function (data) {
alert("Deleted Id: " + id);
$('#exampleModalCenter').modal('hide');