Home » Jquery » jquery – Asp.net mvc how to get webgrid's row values inside a javascript function

jquery – Asp.net mvc how to get webgrid's row values inside a javascript function

Posted by: admin February 22, 2020 Leave a comment

Questions:
@webGrid.GetHtml(
htmlAttributes: new { @id = "WebGrid", @class = "Grid" },
columns: webGrid.Columns(
webGrid.Column("ItemCode", "Item Code"),
webGrid.Column("Name", "Item Name"),
webGrid.Column("Brand", "Brand"),
webGrid.Column(format:@<span class="link"><a class="Delete" href="javascript:;">Delete</a></span> )))

i have a webgrid inside my razor view, when i click delete button i want to display current selected row values (ItemCode, Name , Brand)

my javascript function is

 <script type="text/javascript">
    $("body").on("click", "#WebGrid TBODY .Delete", function () {
        if (confirm("Do you want to delete this row?")) {
            var row = $(this).closest("tr");
            var a = row.get(0);
            alert(a.val())
            row.remove();
        }
    });
</script>

Help me guys!

How to&Answer: