I have the following class:
public class PostCode {
public string Name { get; set; }
public static implicit operator PostCode(string postCode)
{
return new PostCode {Name = postCode};
}
}
It forms part of an Address
class which is the model for a helper template (EditorTemplates>Address.ascx).
This helper template is rendered using <%= Html.EditorFor(model => model.Address)%>
where Address
is the property on another object.
Everything in the address is correctly bound when posting to the action method apart from the PostCode
object. It seems likely that this is due to the fact that it is stored as a PostCode
instead of a string.
How can I force the model binder to honour this cast?