开发者

MVC: In which component do details of data presentation specified?

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?

  1. Property Student of model is a business object, and shall not contain details of rendering.
  2. 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?
  3. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜