开发者

send id from view to controller

开发者 https://www.devze.com 2023-02-19 19:58 出处:网络
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 w开发者_StackOverflow社区ant it to send the id to the method to process it and dele

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 w开发者_StackOverflow社区ant 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 =(


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消