Click here to Skip to main content
15,910,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sir,

I got a question in my asp.net mvc interview which I am unaware.

The question is

I had view containing 2000 lines of code in asp.net mvc. On new client request I had to change the model associated with that view. So I need to overwrite the view loosing 2000 lines. Is there any way to restrict this. So 2000 lines doesn't got affected and also the model change should be reflected on the view too.
Posted
Comments
[no name] 11-Dec-14 23:35pm    
Model change in what sense by the way!!
Anuj Kc 13-Dec-14 23:43pm    
through scaffolding

One solution could be to define a common interface that will be used as model based on the existing model, then the new model must implement this interface.

There a similar discussion about this here: http://stackoverflow.com/questions/17664803/interface-implementing-interface-as-a-view-model-in-asp-net-mvc-4[^]
 
Share this answer
 
Suppose you have 2000 lines of code in your view.It's very hard to maintain those code inside views.You can avoid those lines of code through viewmodel.ViewModel nothing but a wrapper class,whatever the data needed for the view you can set to the viewmodel and pass to the view.So you should create each viewmodel for each view.In this viewmodel you can set all the logics and data for the final view.No need to write those logics inside View.I think interviewer expect the viewmodel concept.

Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900