ASP.NET MVC ViewModel with methods - is it "legal"?

Viewed 8707

Should viewmodels be limited to only have properties, and not methods?

Let's say I have a radio button in my view, and wants to see if the radio button should be checked.

I could do this entirely in my view:

@Html.RadioButton("radiobuttonName", "The value", (id == Model.PersonId)) 

or I could move this logic into the viewmodel:

@Html.RadioButton("radiobuttonName", "The value", Model.IsChecked(id)

using this method in the viewmodel:

    public int PersonId { get;set;}
    public bool IsChecked(int id)
    {
        return (id == PersonId);
    }

Is this OK to do, or should it be done entirely in the view, or in some other way?

2 Answers
Related