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
341 views
in Technique[技术] by (71.8m points)

c# - ASP.NET MVC Form Post

   <form action="/Villa/Add" method="post">
    <table>
        <tr>
            <td>
                Name:
            </td>
            <td>
                <%= Html.TextBox("name") %>
                <%= Html.ValidationMessage("Name") %>
            </td>
        </tr>
                <tr>
                <td>
                </td>
                <td>
                    <input type="submit" value="Add" />
                </td>
            </tr>
        </table>
        </form>

My form is above, how do I retrieve the values in my controller?

Thanks a lot in advance! Hard to find the right material because of different Previews of MVC being released and being different.

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

This works for ASP.Net MVC Beta.

 public ActionResult Add( string name ) {
    ....
 }

 or

 public ActionResult Add( FormCollection form ) {
      string name = form["Name"];
 }

 or

 public ActionResult Add( [Bind(Prefix="")]Villa villa ) {
       villa.Name ...
 }

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

...