2008-11-25 22 views
10
<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> 

Meine Form ist oben, wie kann ich die Werte in meinem Controller abrufen?ASP.NET MVC Formular Post

Vielen Dank im Voraus! Es ist schwer, das richtige Material zu finden, weil MVC anders veröffentlicht wird.

Antwort

21

Dies funktioniert für 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 ... 
} 
5

Haben Sie so etwas wie dies versucht? Pseudocode ...

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