Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6147019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:02:36+00:00 2026-05-23T19:02:36+00:00

Should viewmodels be limited to only have properties, and not methods? Let’s say I

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:02:36+00:00Added an answer on May 23, 2026 at 7:02 pm

    You can have methods in your ViewModel. If it’s a single result you want to calculate each time then I’d suggest adding the evaluation code to your Controller and storing the result in the ViewModel instead but if you need to evaluate things using a method more dynamically and a Property can’t do this for you then doing this in the ViewModel is probably fine.

    In your example above I’d recommend doing this in the ViewModel as then the ViewModel contains the logic in a single place rather than doing this many times copy and pasted in your View.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following view: @model ViewModels.Shared.BaseViewModel <div class=rep_tb0> <div class=rep_tr0> <div class=rep_td0>@Html.LabelFor(model =>
Should i consider ASP.NET MVC ViewModels only containing flat and primitypes types or it
I have some common code written in three ViewModels, which should be refactored. I
Newbie-ish questions ahead: Where should I put my View Model declarations? I created a
So how do you display complex aggregated ViewModels whose Models have relations to each
I have these ViewModels: RecordViewModel, ComponentViewModel where RecordViewModel essentially is a container for several
I Have an MVC Project roughly organized like this: Project 1: MVC app (ViewModels,
I have a substanital WPF application set up as follows: Views, ViewModels, Business Objects
I'm using Prism's EventAggregator for loosely coupled communication between my module's ViewModels. I have
from the design point of view, I have a complex GUI, what is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.