I am quite new to MVC, and am having a bit of trouble submitting a form and having the controller pick up the posted values.
What seems to be happening is that while the form does post to the correct method in the controller, the model that is passed through is full of empty values - as if it's not being populated by the form.
I've tried to create it in the same way as the default Login control, but I'm obviously missing something somewhere. Can anyone please shed any light?
My code is below:
MODEL
Public Class ContactUsDetails Private _name As String Private _email As String Private _details As String Public ReadOnly Property Name() As String Get Return _name End Get End Property Public ReadOnly Property Email() As String Get Return _email End Get End Property Public ReadOnly Property Details() As String Get Return _details End Get End Property Public Sub New(ByVal name As String, ByVal email As String, ByVal details As String) _name = name _email = email _details = details End Sub Public Sub New End Sub End Class VIEW
@ModelType TestMVC.ContactUsDetails @Code ViewData("Title") = "ContactUs" End Code @Using Html.BeginForm() @<fieldset> <legend>Contact Us</legend> <div class="editor-label"> @Html.LabelFor(Function(m) m.Name) </div> <div class="editor-field"> @Html.TextBoxFor(Function(m) m.Name) </div> <div class="editor-label"> @Html.LabelFor(Function(m) m.Email) </div> <div class="editor-field"> @Html.TextBoxFor(Function(m) m.Email) </div> <div class="editor-label"> @Html.LabelFor(Function(m) m.Details) </div> <div class="editor-field"> @Html.TextBoxFor(Function(m) m.Details) </div> <p> <input type="submit" value="Submit" /> </p> </fieldset> End Using CONTROLLER
Namespace TestMVC Public Class FormsController Inherits System.Web.Mvc.Controller ' ' GET: /Forms Public Function ContactUs() As ActionResult Return View() End Function <HttpPost()> _ Public Function ContactUs(model As ContactUsDetails) As ActionResult If ModelState.IsValid Then End If Return View(model) End Function End Class End Namespace