Here I want to get the confirm message when delete button is clicked with out using any jquery for which i have used onclick on Html.Action
as below
<button type="button" class="btn btn-danger" onclick="location.href='@Url.Action("Delete","StudentDetails", new { id=item.StudentId}, new { onclick = "return confirm('Are sure wants to delete?');" } )'"><i class="fa fa-trash" aria-hidden="true"></i></button><br>
But it shows an error saying "cannot convert from '<anonymous type: int id>'to 'System.Web.Routing.RouteValueDictionary'>"
on new { id=item.StudentId}
and Cannot convert from '<anonymous type:string onclick>'to 'string'
Any Help will be great
It might be easier to split this out.
Add the URL to a data attribute, something like
<button data-url="@Url.Action("Delete","StudentDetails", new { id=item.StudentId})" onclick="ConfirmDeletion()"></button>
Then onclick can call a javascript function
function ConfirmDeletion()
{
var x = confirm("Are you sure you want to delete?");
if (x) {
var url = this.getAttribute('data-url')
location.href= = url;
}
}
I haven't tested this but I think its simpler and clearer
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.