Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
169 views
in Technique[技术] by (71.8m points)

asp.net mvc - How to pass in ID with Html.BeginForm()?

In ASP.NET MVC I'm using the HTML helper

Html.BeginForm("ActionName", "Controller", FormMethod.Post);

But I need to post to: /controller/action/23434

How do I pass in the ID?

question from:https://stackoverflow.com/questions/878330/how-to-pass-in-id-with-html-beginform

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Matt's should work fine. If you are still passing in FormMethod.Post, though, you need to do it like this:

Html.BeginForm("action","controller", new { Id = 12345 }, FormMethod.Post);

Reversing the third and fourth parameters will result in the Id being treated as an attribute instead of a route value.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...