Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC Form Post

Tags:

c#

asp.net-mvc

   <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.

like image 383
Tablet Avatar asked Nov 25 '08 12:11

Tablet


1 Answers

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 ...
 }
like image 187
tvanfosson Avatar answered Sep 21 '22 00:09

tvanfosson