tags:

views:

43

answers:

2

I have the below view model that has both school and Address objects like

namespace myapplication.ViewModels
{ 
    public class SchoolViewModel
    {
        public Address schoolAddress { get; set; }
        public School school { get; set; } 

    }
} 

and I have student,teacher and other objects that has address with addressId field, when I create the school object, since school object has addressID, I have to create both the address object and school object by making partial view for address object,so that I will not repeat the address fields for all objects that require address. so the school create view will have SchoolViewModel,to accept both object fields.so the Create View is strongly typed view of SchoolViewModel object. And for address create I make strongly typed of partial view with Model.schoolAddress object. The problem is Model.schoolAddress is null. like <% Html.RenderPartial("addressPartilaView", Model.schoolAddress);%> but when the address partial view is strongly typed of SchoolViewModel object I can get the value of schoolAddress. please ,please would you give me some idea about this, or how can I proceed with other solutions?

A: 

I'd really recommend re-writing your question so it's clearer.

However, after struggling with trying to decipher what you mean, I think the problem is that you are sometimes passing schoolAddress as the model and then still expecting the model to have a property of schoolAddress.

If you do

<% Html.RenderPartial("addressPartialView", Model.schoolAddress);%> 

Then the Model in addressPartialView won't have a schoolAddress property, it will be an instance of schoolAddress.

Of course, if this is well off base, then I'd strongly suggest rewording the original question.

Matt Lacey
A: 

thanks, sure you get my problem, I really want to send the instance of Model.SchoolAddress object to the partial view. But the problem is Model.SchoolAddress is null.

helen