0
votes

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?

1
Please sorry for my way of writing, I was in a hurry when I post it.helen

1 Answers

0
votes

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.