Example is fake.
ASP.NET MVC: I have a view that renders a student info. Student info consists of First Name, Last Name and (optional) Age (declared as int?
).
Student info is rendered something like, if age is not specified I want to show "not specified":
<span><%= Model.Student.FirstName %></span>
<span><%= Model.Student.LastName %></span>
<span><%= Model.Student.Age.HasValue ? Model.Student.Age.ToString() : "not specified" %></span>
My problem with text above is that it makes view too complicated (too complicated for my web designer to be able to mod开发者_开发百科ify it).
Question: Where could I move that decision?
- Property
Student
of model is a business object, and shall not contain details of rendering. - Should I add a method to Model:
Model.GetAgeAsText(Student student)
? But then I end up with a host of loosely hanging methods on Model, that are crying to be grouped into something...but what? - I could create a custom control
StudentAgeShower
, this appears to be the most OO-correct solution, but seems to be bit overkill.
Any suggestions?
Create a View Model of a Student with all the decisions premade.
精彩评论