Timeless
Timeless

Reputation: 7547

Can I include View in Model in MVC3

I have a model, which Area is the Google map overlay(area) details and AreaData is the data used to render the area in the google map.

public class AreaDetailsViewModel
{
     public Area Area{get;set;}
     public AreaData Data{get;set;}
}

the problem now is i'm trying to use ajax call to retrieve view and data at the same time.

but if i return the whole data as json, i wont get view; if i return as html, i will include the areadata into html.

because i need to localize the view, i cannt just retrieve the data without the localized label info.

so can i include the view into model?

public class AreaDetailsViewModel
{
     public View AreaView{get;set;}
     public AreaData Data{get;set;}
}

but it seems weird, i really need your advice.

Upvotes: 1

Views: 145

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039298

The way MVC works is that you have a view (could be HTML, partial HTML, JSON, XML, ...) and a controller action which populates a model (all the data that the view needs in order to display) and passes this model to the view.

So in your example you could have a controller action which will be queried using an AJAX call and which passes the model to a partial view which will display this data in the desired format.

Upvotes: 1

Related Questions