asp.net mvc - Is it acceptable to place view logic in a strongly typed view-data class? -


Say you have found a scene for which some data is needed, for which some calculation is required, but no external There is no dependence. (For example, a numbered string list of the last 5 years.) Is it acceptable to put it in a strictly typed visual category?

Something like this:

  class HomeIndexViewData {// ... some visual data ... public IEnumerable & lt; String & gt; LastThreeYears {{Return to new string} [DateTime.Now.Year.ToString (), (Datetime.now.year - 1) .restring (), (datetime.now.year - 2) .restring ()}; }}}  

Now, what if this calculation is dependent on some other properties in the visual data class? Let's say if the year appears in the list of dates, then does this 'Last Two Year' property add a star to the end of the year?

Disclaimer: This is specific to only one view and is only for one data, a repository, visual model, etc. can not be handled properly.

On the one hand, I think view data must be: A lifeless collection of properties which are passed only by the view controller. On the other hand, it is very beautiful.

Personally, I will do this. I think the property is fine. If you consider it to be an idea model, then look at such log-in this way, is not it? This is definitely better than the sparked spaghetti code with the markout (I do not like it, though sometimes there is no move).

This property is readable only, the result of this is done for a result, especially to see that I have a vote - yes, go for it.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -