Usuń ActionLink z oknem potwierdzenia
Próbuję zaimplementować prosty ActionLink
, który usunie rekordy za pomocą ASP.NET MVC. To jest to co mam do tej pory:
<%= Html.ActionLink("Delete",
"Delete",
new { id = item.storyId,
onclick = "return confirm('Are you sure?');"
})%>
Jednak nie pokazuje pola potwierdzenia. Najwyraźniej czegoś mi brakuje lub źle zbudowałem link. Czy ktoś może pomóc?
9 answers
Nie myl routeValues
z htmlAttributes
. Prawdopodobnie chcesz to przeciążenie :
<%= Html.ActionLink(
"Delete",
"Delete",
new { id = item.storyId },
new { onclick = "return confirm('Are you sure you wish to delete this article?');" })
%>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-01-13 16:00:31
To są drogi, które mijasz
<%= Html.ActionLink("Delete", "Delete",
new { id = item.storyId },
new { onclick = "return confirm('Are you sure you wish to delete this article?');" }) %>
Przeciążona metoda, której szukasz, to ta:
public static MvcHtmlString ActionLink(
this HtmlHelper htmlHelper,
string linkText,
string actionName,
Object routeValues,
Object htmlAttributes
)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-01-13 16:00:03
<%= Html.ActionLink("Delete", "Delete",
new { id = item.storyId },
new { onclick = "return confirm('Are you sure you wish to delete this article?');" }) %>
Powyższy kod działa tylko dla Html.ActionLink.
Dla
Ajax.ActionLink
Użyj następującego kodu:
<%= Ajax.ActionLink(" ", "deleteMeeting", new { id = Model.eventID, subid = subItem.ID, fordate = forDate, forslot = forslot }, new AjaxOptions
{
Confirm = "Are you sure you wish to delete?",
UpdateTargetId = "Appointments",
HttpMethod = "Get",
InsertionMode = InsertionMode.Replace,
LoadingElementId = "div_loading"
}, new { @class = "DeleteApointmentsforevent" })%>
Opcja 'Confirm' określa pole potwierdzenia javascript.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-03-11 08:55:07
Można również dostosować, przekazując element delete wraz z wiadomością. W moim przypadku za pomocą MVC i Razor, więc mogę to zrobić:
@Html.ActionLink("Delete",
"DeleteTag", new { id = t.IDTag },
new { onclick = "return confirm('Do you really want to delete the tag " + @t.Tag + "?')" })
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-02-12 14:39:15
Używając webgrid można go znaleźć tutaj , Linki do akcji mogą wyglądać następująco.
grid.Column(header: "Action", format: (item) => new HtmlString(
Html.ActionLink(" ", "Details", new { Id = item.Id }, new { @class = "glyphicon glyphicon-info-sign" }).ToString() + " | " +
Html.ActionLink(" ", "Edit", new { Id = item.Id }, new { @class = "glyphicon glyphicon-edit" }).ToString() + " | " +
Html.ActionLink(" ", "Delete", new { Id = item.Id }, new { onclick = "return confirm('Are you sure you wish to delete this property?');", @class = "glyphicon glyphicon-trash" }).ToString()
)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-09-24 11:36:07
Z obrazem i potwierdzeniem na delete, który działa na Mozilli firefox
<button> @Html.ActionLink(" ", "action", "controller", new { id = item.Id }, new { @class = "modal-link1", @OnClick = "return confirm('Are you sure you to delete this Record?');" })</button>
<style>
a.modal-link{ background: URL(../../../../Content/Images/Delete.png) no-repeat center;
display: block;
height: 15px;
width: 15px;
}
</style>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-23 13:17:49
Spróbuj tego:
<button> @Html.ActionLink(" ", "DeletePhoto", "PhotoAndVideo", new { id = item.Id }, new { @class = "modal-link1", @OnClick = "return confirm('Are you sure you to delete this Record?');" })</button>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-24 01:14:59
Każde zdarzenie kliknięcia przed aktualizacją / edycją/usunięciem rekordów powiadomi Użytkownika, a jeśli "Ok" Kontynuuj akcję, inne "anuluj" pozostaną niezmienione. Dla tego kodu nie ma potrzeby oddzielnego kodu java script. it works for me
<a asp-action="Delete" asp-route-ID="@Item.ArtistID" onclick = "return confirm('Are you sure you wish to remove this Artist?');">Delete</a>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-10-25 07:44:54
Możesz również spróbować tego dla Html.ActionLink DeleteId
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-07-30 19:44:26