I have a simple object
public class SomeObject
{
public Int32 id { get; set; }
public string name { get; set; }
}
In a strongly typed view I am letting the user edit SomeObject.name, when the form is posted the receiving method doesn’t see SomeObject.id in FormCollection (it does see SomeObject.name). Do I need to actually place every object property in the form to be able to access them when form is posted?
What’s the best practice, should I just insert hidden fields for each property I don’t plan letting the user edit? maybe I should place the entire object in the ViewData?
Thanks
FormCollectioncontains only properties that have been posted either through text fields or hidden fields. So if you need to use theIdproperty in your controller action you need to include it in your form. Depending on what you are doing in your controller action you might or might not include it. It is not necessary to include hidden fields for each property.Usually the
Idis sufficient because it allows you to later retrieve the object from your data store given this id.