asp.net mvc - Should MVC models contain content just for the response -


i have quiz style mvc application. i'm passing in view:

public class question{     public int questionid;     public string questiontext;     public string answertext;     public int answer; } 

however in response need (and get) 2 int properties, null string values. question is, think model should contain 2 int properties , should pass in string properties in viewdata/viewbag?

in answer question, yes, believe should. in case create answer class gets returned view , contains 2 int properties interested in:

public class answer{     public int questionid;     public int answer; } 

your controller action receives can accept parameter of type answer, model binding correctly populate. if don't need string properties returned view, don't pass them across. if need them, add them answer class. there's no need use viewdata or viewbag @ all. rename them questionviewmodel , answerviewmodel per @emre-nevayeshirazi's suggestion. map these equivalent domain classes before passing them domain layer.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -