asp.net mvc - MVC 2 model properties not used in view returned as null or empty -


The issue I am getting is when I pass a populated object to a view that displays all the properties does not do.

  Edit Public Functionality (Guide Client ID) {Property Property = Property Model. GetPropertyDetails (clientID); See Return ("Edit", "Site", Property); }   

See:

  & lt;% @ page title = "" language = "c #" inheritance = "system web.mvc viewpage & Lt; WebFrontend .ViewModels.Property & gt; "& Gt%; Use of & lt;% (Html.BeginForm ()) {%> & Lt;%: Html.ValidationSummary (True, "asset update was unsuccessful. Please fix the errors and try again.")% & Gt; & Lt; Fieldset & gt; & Lt; Legend & gt; Edit Account: & lt;%: Model.ClientAccountNo% & gt; & Lt; / Legend & gt; & Lt; Div class = "editor-label" & gt; & Lt;%: HTML.LabelFor (Model = & gt; model.ClientName)% & gt; & Lt; / Div & gt; & Lt; Div class = "editor-field" & gt; & Lt;%: Html.TextBoxFor (model = & gt; model.ClientName)% & gt; & Lt;%: HTML Validation message (model = & gt; model.ClientName)%> & Lt; / Div & gt; & Lt; P & gt; & Lt; Input type = "submit" value = "update property" / & gt; & Lt; / P & gt; & Lt; / Fieldset & gt; & Lt;%}% & gt;   

When the asset object submitted has passed this controller method, but all the properties that are not used in the view are empty including models. Not a client account that exists on the scene before presenting. / P>

  [http post] Edit Public Action Result (Property Property) {if (ModelState.IsValid) {bool success = PropertyModel.UpdateProperty (property); If (the success) {// property has been updated, take them back to the property details screen Return the return action ("Details", "Property", New {clientID = property.ClientID}); } Other {ModelState.AddModelError ("", "Property could not be updated."); View refund ("active", "site", property); }} // If we have found this, then some failed, see Show Form Returns ("Edit", "Site", Property); }   

I can not find any equal on the web, why there is any explanation about this and how it is decided, it will be appreciated.

This is the way that MVC works - this is the path, form and query parameters in the query string Tries to create an object of type. In your case it can only get value in the form collection. It does not know anything about the values ​​stored in your database.

If you are interested only in some qualities, then you will be better off with a specific visual model - then you can validate for this specific case.

If you store values ​​in hidden areas, then they can be kept in mind - if this is a problem, then definitely go with a special visual model along with editable fields. Are there. >

Comments