Note that there are some explanatory texts on larger screens.

plurals
  1. POHelp with passing an object back to post action please
    primarykey
    data
    text
    <p>I have a get method passing in an object of type Store to the view, upon creating the view using the menu dialog (i.e. Create a strongly-typed view) it properly scaffolds out the form when I choose the view content to be Edit. Without changing anything on the view I add a post method that accepts a store object as the parameter. The properties on the object are never populated with the form data and I am unable to figure out why. A Request.Form.Count shows 14 items which is correct minus the Id which would make 15. If I type out each parameter separately they do get set. I can also use the FormCollection to get the values, but sure would be nice to pass the entire object back in and use that.</p> <p>Is there a reason why this might be happening?</p> <p>Store Definition:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DomainModel { public class Store : GuidIdentityPersistenceBase { private string _address1; private string _address2; private string _city; private string _county; private int _oldStoreNumber; private string _faxNumber; private bool _hasHydraulicHose; private bool _hasInsCounter; private bool _hasPaintBooth; private bool _isHubStore; private bool _isOpenNightsWeekends; private int _newStoreNumber; private string _phoneNumber; private string _postalCode; private string _state; private IList _walls = new List(); public virtual string Address1 { get { return _address1; } set { _address1 = value; } } public virtual string Address2 { get { return _address2; } set { _address2 = value; } } public virtual string City { get { return _city; } set { _city = value; } } public virtual string County { get { return _county; } set { _county = value; } } public virtual int OLDStoreNumber { get { return _oldStoreNumber; } set { _oldStoreNumber = value; } } public virtual string FaxNumber { get { return _faxNumber; } set { _faxNumber = value; } } public virtual bool HasHydraulicHose { get { return _hasHydraulicHose; } set { _hasHydraulicHose = value; } } public virtual bool HasInsCounter { get { return _hasInsCounter; } set { _hasInsCounter = value; } } public virtual bool HasPaintBooth { get { return _hasPaintBooth; } set { _hasPaintBooth = value; } } public virtual Guid Id { get { return _persistenceId; } } public virtual bool IsHubStore { get { return _isHubStore; } set { _isHubStore = value; } } public virtual bool IsOpenNightsWeekends { get { return _isOpenNightsWeekends; } set { _isOpenNightsWeekends = value; } } public virtual int NewStoreNumber { get { return _newStoreNumber; } set { _newStoreNumber = value; } } public virtual string PhoneNumber { get { return _phoneNumber; } set { _phoneNumber = value; } } public virtual string PostalCode { get { return _postalCode; } set { _postalCode = value; } } public virtual string State { get { return _state; } set { _state = value; } } public virtual IList Walls { get { return _walls.ToList().AsReadOnly(); } } public virtual void AddWall(Wall wall) { wall.Store = this; _walls.Add(wall); } } }</code></pre> <p>Get Action:</p> <pre><code>[AcceptVerbs(HttpVerbs.Get)] public ViewResult EditStore(Guid Id) { Store store; using (UnitOfWork.Start()) { store = _storeRepository.GetStore(Id); } return View(store); }</code></pre> <p>Post Action (yes I realize there are no encoding checks etc, just rough here at first):</p> <pre><code>[AcceptVerbs(HttpVerbs.Post)] public ActionResult EditStore(Store store) { using (UnitOfWork.Start()) { _storeRepository.Update(store); UnitOfWork.Current.Flush(); } return RedirectToAction("EditStore", store.Id); }</code></pre> <p><code> &lt;% using (Html.BeginForm()) {%></p> <pre><code> &lt;fieldset&gt; &lt;legend&gt;Fields&lt;/legend&gt; &lt;p&gt; &lt;label for="Address1"&gt;Address1:&lt;/label&gt; &lt;%= Html.TextBox("Address1", Model.Address1) %&gt; &lt;%= Html.ValidationMessage("Address1", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="Address2"&gt;Address2:&lt;/label&gt; &lt;%= Html.TextBox("Address2", Model.Address2) %&gt; &lt;%= Html.ValidationMessage("Address2", "*") %&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;label for="County"&gt;County:&lt;/label&gt; &lt;%= Html.TextBox("County", Model.County) %&gt; &lt;%= Html.ValidationMessage("County", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="OLDStoreNumber"&gt;OLDStoreNumber:&lt;/label&gt; &lt;%= Html.TextBox("OLDStoreNumber", Model.OLDStoreNumber) %&gt; &lt;%= Html.ValidationMessage("OLDStoreNumber", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="FaxNumber"&gt;FaxNumber:&lt;/label&gt; &lt;%= Html.TextBox("FaxNumber", Model.FaxNumber) %&gt; &lt;%= Html.ValidationMessage("FaxNumber", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="HasHydraulicHose"&gt;HasHydraulicHose:&lt;/label&gt; &lt;%= Html.TextBox("HasHydraulicHose", Model.HasHydraulicHose) %&gt; &lt;%= Html.ValidationMessage("HasHydraulicHose", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="HasInsCounter"&gt;HasInsCounter:&lt;/label&gt; &lt;%= Html.TextBox("HasInsCounter", Model.HasInsCounter) %&gt; &lt;%= Html.ValidationMessage("HasInsCounter", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="HasPaintBooth"&gt;HasPaintBooth:&lt;/label&gt; &lt;%= Html.TextBox("HasPaintBooth", Model.HasPaintBooth) %&gt; &lt;%= Html.ValidationMessage("HasPaintBooth", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="IsHubStore"&gt;IsHubStore:&lt;/label&gt; &lt;%= Html.TextBox("IsHubStore", Model.IsHubStore) %&gt; &lt;%= Html.ValidationMessage("IsHubStore", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="IsOpenNightsWeekends"&gt;IsOpenNightsWeekends:&lt;/label&gt; &lt;%= Html.TextBox("IsOpenNightsWeekends", Model.IsOpenNightsWeekends) %&gt; &lt;%= Html.ValidationMessage("IsOpenNightsWeekends", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="NewStoreNumber"&gt;NewStoreNumber:&lt;/label&gt; &lt;%= Html.TextBox("NewStoreNumber", Model.NewStoreNumber) %&gt; &lt;%= Html.ValidationMessage("NewStoreNumber", "*") %&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="PostalCode"&gt;PostalCode:&lt;/label&gt; &lt;%= Html.TextBox("PostalCode", Model.PostalCode) %&gt; &lt;%= Html.ValidationMessage("PostalCode", "*") %&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;input type="submit" value="Save" /&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;% } %&gt; &lt;div&gt; &lt;%=Html.ActionLink("Back to List", "Index") %&gt; &lt;/div&gt; </code></pre> <p></code></p> <p>Fiddler:</p> <pre><code>Address1=1234+Main+street&Address2=Suite+100&City=Anywhere&County=MyCounty&OLDStoreNumber=1&FaxNumber=18001112222&HasHydraulicHose=true&HasHydraulicHose=false&HasInsCounter=true&HasInsCounter=false&HasPaintBooth=false&IsHubStore=false&IsOpenNightsWeekends=false&NewStoreNumber=1&PhoneNumber=18001112222&PostalCode=11001&State=MyState</code></pre>
    singulars
    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.
    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