ASP.NET MVC 1.0 nested models with partial views
صفحه اصلي

ASP.NET MVC 1.0 nested models with partial views

I'm trying to get a nested model to bind correctly with a nested view but am not having any luck.

Here is a detailed look

This is the class

public class Foo {      public AnotherClass AnotherClass { get; set; }     public string Name { get; set; }     public ...... } 

Inside AnotherClass we have more sub objects such as

public class AnotherClass  {     public AThirdClass { get; set; } } 

The third class has the properties that we want to bind to.

public class AThirdClass {     public string ImportantString { get; set; }     public string SecondString { get; set; } } 

The primary view is expecting a class of type Foo. Inside of that View we call the html helper to render the partial view which expects a model of type AnotherClass which we pass in. The call would be

<% Html.RenderPartial("MyPartialView", Model.AnotherClass); %> 

Inside the partial view MyPartialView we have text boxes for editing fields in AThirdClass and they are set up like this

<%= Html.TextBox("AThirdClass.ImportantString", Model.AThirdClass.ImportantString) %> 

When we post back to the server I'm loosing all the data that was entered in the text box. Is this not supported in MVC 1.0? I am able to use this technique if I don't have any partial views while still using nested objects?

It looks like in MVC 2.0 you can use the EditorFor HTML helper to do what I need to do however I'm stuck on MVC 1.0.

What am I doing wrong?

how to make a session persistent with .net


Getting session data in MVC actions with AuthorizeAttribute
I've got a job around for this.. Why jquery ajax calls fails after session timeout in mvc? If you pass the full view model into the partial and then reference the sub objects right from the top model then you will be fine. ASP.NET or ASP.NET MVC or Silverlight or a mixture?. Why are my aspx pages not being cached on the client? I would still like to hear how anyone else has done this though.. Multible jquery .load() methods not running concurrently in MVC 2
How 404 error mvc 2 IIS 7?ASP.NET MVC Error: Page is not allowed here because it does not extend class 'System.Web.Page'


I'm on MVC 3, still have this same issue, switched to less than ideal inheritance. If anyone knows a better way please post it..

94 out of 100 based on 39 user ratings 154 reviews