Given the following classes and controller action method:
public School
{
public Int32 ID { get; set; }
publig String Name { get; set; }
public Address
Just additional information: Check this ASP.NET MVC issue #2403.
Until the issue is fixed, I use my own extension methods like Html.TextBoxFixed, etc. that simply replaces dots with underscores in the id attribute (not in the name attribute), so that you use jquery like $("#Address_Street") but on the server, it's like Address.Street.
Sample code follows:
public static string TextBoxFixed(this HtmlHelper html, string name, string value)
{
return html.TextBox(name, value, GetIdAttributeObject(name));
}
public static string TextBoxFixed(this HtmlHelper html, string name, string value, object htmlAttributes)
{
return html.TextBox(name, value, GetIdAttributeObject(name, htmlAttributes));
}
private static IDictionary GetIdAttributeObject(string name)
{
Dictionary list = new Dictionary(1);
list["id"] = name.Replace('.', '_');
return list;
}
private static IDictionary GetIdAttributeObject(string name, object baseObject)
{
Dictionary list = new Dictionary();
list.LoadFrom(baseObject);
list["id"] = name.Replace('.', '_');
return list;
}