-1

I am currently using Url.Action for buttons on my dashboard and I would keep this consistent UI.

I have a delete button which I now want to implement a pop up box for to avoid mistake deletes.

I have achieved this using Html.Action link but I quickly learnt that I cannot put this inside an tag. Can someone please aid me in making the equivalent to end up with a button? Thanks.

Url.Action Code

<input type="submit" value="Delete" onclick="location.href='@Url.Action("Action","Controller", new {refNumber = item.RefNumber, null}'"/>

Html.ActionLink Code

@Html.ActionLink("Action","Controller", new {refNumber = item.RefNumber}, new {onclick="return confirm('Are you sure?');"})
steve
  • 797
  • 1
  • 9
  • 27
  • 1
    `Url.Action()` is exactly what you need. – SLaks Jul 24 '18 at 21:45
  • Yeah but I said I need to need to implement a pop up which the html.actionlink does and not url.action – steve Jul 24 '18 at 21:47
  • 1
    Don't use Html.ActionLink for this, use Url.Action inside an input type=button. Better yet, make your Delete Action a POST, deletes and GET's dont do well. – mxmissile Jul 24 '18 at 21:48
  • thanks, but that does not answer my question, I just want a pop-up, the application works perfectly fine. I cannot use new {onclick="return confirm} inside Url.Action 4th parameter, else I would not leave it null. – steve Jul 24 '18 at 21:50
  • 1
    A Delete action is altering data - it needs to be a POST method, not a GET –  Jul 24 '18 at 21:52

1 Answers1

0

Try this...

<a href="@Url.Action("Action","Controller", new {refNumber = item.RefNumber, null})" onclick="return confirm('are you sure?');">Delete</a>

As mentioned in the comments, I'd highly recommend changing your action to a POST. Can read more about that here.

mxmissile
  • 11,464
  • 3
  • 53
  • 79
  • thanks so much! I embedded an input tag inside the and I now have it functioning like a button! and yeah thanks I will definitely read into it, I'm still just a junior developer so I will take every tip I can get! gracias! – steve Jul 24 '18 at 22:16