I am trying to correctly bind a nested model to a nested view, but I'm out of luck.
Here is a detailed overview
This is class
public class Foo { public AnotherClass AnotherClass { get; set; } public string Name { get; set; } public ...... }
Inside AnotherClass, we have more subelements like
public class AnotherClass { public AThirdClass { get; set; } }
The third class has properties that we want to bind to.
public class AThirdClass { public string ImportantString { get; set; } public string SecondString { get; set; } }
The main view expects a class of type Foo. Inside this view, we call the html helper to display the partial view that the model of the AnotherClass type that we are passing expects. The call will be
<% Html.RenderPartial("MyPartialView", Model.AnotherClass); %>
Inside the partial view of MyPartialView, there are text fields for editing fields in AThirdClass, and they are configured as follows
<%= Html.TextBox("AThirdClass.ImportantString", Model.AThirdClass.ImportantString) %>
When we send back to the server, I lose all the data that was entered in the text box. Is this not supported in MVC 1.0? Can I use this technique if I don't have partial views when using nested objects?
It looks like in MVC 2.0 you can use the EditorFor HTML helper to do what I need, but I'm stuck on MVC 1.0.
What am I doing wrong?
user172632
source share