Note that there are some explanatory texts on larger screens.

plurals
  1. POSome Fields Not Coming Through In ModelBinder
    primarykey
    data
    text
    <p>The following is the code for my controller:</p> <pre><code> [AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(int id, Actor actor) { try { actorRepository.Save(actor); return RedirectToAction("Index"); } catch { return View("Edit"); } } </code></pre> <p>The view that calls has a partial view that is strongly typed to the Actor class. For some reason, there are a few fields that are not being bound to the class. The fields in question are Address, Address2, and ZipCode. They are populated on the page, but they come back null. Every other field is there, just not these.</p> <p>Any ideas? Also, how could I write a unit test to duplicate this behavior?</p> <p><strong>Update</strong> public class Actor { public string MiddleName{ get; set;}</p> <pre><code> [Required(ErrorMessage = "First Name is Required")] [RegularExpression(@"\w*", ErrorMessage = "Last Name Contains Illegal Characters")] public string FirstName { get; set; } [Required(ErrorMessage = "Last Name is Required")] [RegularExpression(@"\w*", ErrorMessage = "Last Name Contains Illegal Characters")] public string LastName { get; set; } [DataType(DataType.PhoneNumber, ErrorMessage = "Please Enter a Valid Phone Number")] [Required(ErrorMessage = "Phone Number is Required")] public string PhoneNumber { get; set; } [Required(ErrorMessage = "Address is Required")] [RegularExpression(@"\w*", ErrorMessage = "Address Contains Illegal Characters")] public string Address { get; set; } [RegularExpression(@"\w*", ErrorMessage = "Address2 Contains Illegal Characters")] public string Address2 { get; set; } [RegularExpression(@"\w*",ErrorMessage = "State Contains Illegal Characters")] [Required(ErrorMessage = "State is Required")] public string State { get; set; } [Required(ErrorMessage = "Zip Code is Required")] [RegularExpression("\b[0-9]{5}(?:-[0-9]{4})?\b",ErrorMessage = "Please Enter a Valid Zip Code")] public string ZipCode { get; set; } [Required(ErrorMessage = "Even in theater, you have to choose a gender")] public bool? Gender { get; set; } [Required(ErrorMessage = "Cell Phone Number is Required")] public string CellPhone { get; set; } public int ActorId { get; set; } [DataType(DataType.MultilineText, ErrorMessage = "Illegal Characters in Notes")] public string Notes { get; set; } [Required(ErrorMessage = "Email Address is Required")] [DataType(DataType.EmailAddress)] public string EMail { get; set; } [Required(ErrorMessage = "City Is Required")] public string City {get; set;} } &lt;fieldset&gt; &lt;legend&gt;Fields&lt;/legend&gt; &lt;p&gt; &lt;label for="MiddleName"&gt;MiddleName:&lt;/label&gt; &lt;%= Html.EditorFor(m=&gt;m.MiddleName) %&gt; &lt;%= Html.ValidationMessage("MiddleName", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="FirstName"&gt;FirstName:&lt;/label&gt; &lt;%=Html.EditorFor(m=&gt;m.FirstName) %&gt; &lt;%= Html.ValidationMessage("FirstName", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="LastName"&gt;LastName:&lt;/label&gt; &lt;%= Html.TextBox("LastName", Model.LastName) %&gt; &lt;%= Html.ValidationMessage("LastName", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="PhoneNumber"&gt;PhoneNumber:&lt;/label&gt; &lt;%= Html.TextBox("PhoneNumber", Model.PhoneNumber) %&gt; &lt;%= Html.ValidationMessage("PhoneNumber", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="Address"&gt;Address:&lt;/label&gt; &lt;%=Html.EditorFor(m=&gt;m.Address) %&gt; &lt;%= Html.ValidationMessage("Address", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="Address2"&gt;Address2:&lt;/label&gt; &lt;%=Html.EditorFor(m=&gt;m.Address2) %&gt; &lt;%= Html.ValidationMessage("Address2", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="State"&gt;State:&lt;/label&gt; &lt;%= Html.TextBox("State", Model.State) %&gt; &lt;%= Html.ValidationMessage("State", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="ZipCode"&gt;ZipCode:&lt;/label&gt; &lt;%= Html.TextBox("ZipCode", Model.ZipCode) %&gt; &lt;%= Html.ValidationMessage("ZipCode", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="Gender"&gt;Gender:&lt;/label&gt; &lt;%= Html.TextBox("Gender", Model.Gender) %&gt; &lt;%= Html.ValidationMessage("Gender", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="CellPhone"&gt;CellPhone:&lt;/label&gt; &lt;%= Html.TextBox("CellPhone", Model.CellPhone) %&gt; &lt;%= Html.ValidationMessage("CellPhone", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="ActorId"&gt;ActorId:&lt;/label&gt; &lt;%= Html.TextBox("ActorId", Model.ActorId) %&gt; &lt;%= Html.ValidationMessage("ActorId", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="Notes"&gt;Notes:&lt;/label&gt; &lt;%= Html.TextBox("Notes", Model.Notes) %&gt; &lt;%= Html.ValidationMessage("Notes", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="EMail"&gt;EMail:&lt;/label&gt; &lt;%= Html.TextBox("EMail", Model.EMail) %&gt; &lt;%= Html.ValidationMessage("EMail", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="City"&gt;City:&lt;/label&gt; &lt;%= Html.TextBox("City", Model.City) %&gt; &lt;%= Html.ValidationMessage("City", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;input type="submit" value="Save" /&gt; &lt;/p&gt; &lt;/fieldset&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload