asleep
asleep

Reputation: 4084

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.

Upvotes: 10

Views: 35902

Answers (3)

tvanfosson
tvanfosson

Reputation: 532665

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

Upvotes: 20

Jeff Sheldon
Jeff Sheldon

Reputation: 2104

Have you tried something like this? Pseudocode...

public class VillaController : Controller 
{
      public ActionResult Add(string name)
      {
          // Code...
      }
}

Upvotes: 5

Mariusz
Mariusz

Reputation: 1409

It belongs to your url routes, you defined.

In your case the form ist looking for an controller named "Villa" and the action inside of it named "Add".

Maybe you should read ScottGu's blog post: http://weblogs.asp.net/scottgu/archive/2008/09/02/asp-net-mvc-preview-5-and-form-posting-scenarios.aspx

Upvotes: 1

Related Questions