asp.net - MVC. Bind TextBoxFor to a Field of type object -
suppose following code:
public class person { public object age { get; set;} } inside view:
@html.textboxfor(x => x.age, new { @type = "number" }) now when posting form, typeof person.age property string[1]. why?
shouldn't there input type based, type pick-up logic, when binding things?
you can't use *for helpers property of type object. these helpers need type inference in order create right type of input right name , attributes. object literally anything.
i'm not sure why you're using object property age (isn't int?). however, if need that, recommend using view model can define more concrete type purposes of view. then, can map posted value onto object property.
Comments
Post a Comment