bb2
bb2

Reputation: 97

send id from view to controller

I have a view that receives a Model and displays info of that model. I have a submit button and when it is clicked i want it to send the id to the method to process it and delete a row that has such id.

How can I do this? I want to use a button not an html link like

@Html.ActionLink("Delete", "Delete", new { id = Model.Id }) |

Thanks!

I tried input type hidden but hasn't worked =(

Upvotes: 1

Views: 1422

Answers (1)

jlnorsworthy
jlnorsworthy

Reputation: 3974

You can use a form to do this... I don't use razor, but an equivalent .aspx way to do this would be:

<%using (Html.BeginForm("Home", "myaction", new { Id = 1 }))
  { %>
    <input type="submit" value="submit" />
<%} %>

This will post to ~/Home/myaction/1

Just call Html.BeginForm with the appropriate razor syntax.

Upvotes: 2

Related Questions