MVC Confirmation Dialog


To get a decent looking dialog working without too much hassle, we will make use of the jQuery UI library.

First install NuGet package jQueryUI.Combined, and then, just add the following code (adjust as needed).
Notice that the Delete link (href) calls the confirmDelete JavaScript method.

foreach (var item in Model)
            @Html.DisplayFor(modelItem => item.Title)
            <a href="@Url.Action("Edit", "Notes", new { noteId = item.NoteId })">
                <i class="glyphicon glyphicon-edit"></i>
            <a href="#" onclick="javascript:confirmDelete('@item.NoteId')">
                <i class="glyphicon glyphicon-trash"></i>

<div id="dialogBox" title="Confirm Delete"></div> 

<script src="~/Scripts/jquery-3.6.0.js"></script>
<script src="~/Scripts/jquery-ui-1.12.1.js"></script>
<link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" />

<script type="text/javascript">
    let noteId = ''; 

    $(function () {
            resizable: false,
            height: 200,
            autoOpen: false,
            modal: true,
            buttons: {
                "Yes": function () {
                    var url = '@ViewBag.baseUrl' + "Notes/Delete/" + noteId;
                "No": function () {

    function confirmDelete(nid)
        noteId = nid;
        document.getElementById("dialogBox").innerHTML = "Are you sure you want to delete note:<br/> <b>" + nid + "</b>?";