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 7601203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:06:43+00:00 2026-05-30T23:06:43+00:00

My database table for buildings stores the building type as a code. In a

  • 0

My database table for buildings stores the building type as a code. In a separate lookup table the description for that code is stored.

How should I design my ViewModel and where will I need to make the call to get the associated description value?

I sort of can see one option. I want to know if there is a better option.

BuildingViewModel
{
 public string BuildingTypeCode { get;set;}  
 ...other properties
}

Then in my view

code...

<p>@MyService.GetDescription(Model.BuildingTypeCode)</p>

...code

Am I incorrect in the way I am thinking? if I do the above I create a dependency in my View to the service?

Update 1

Working through some of the solutions offered. I seem to run into another issue. I can’t access the constructor of each building directly…

    public ViewResult Show(string ParcelId)
    {
        var result = _service.GetProperty(ParcelId);
        var AltOwners = _service.GetAltOwners(ParcelId);
        var Buildings = _service.GetBuildings(ParcelId);

        ParcelDetailViewModel ViewModel = new ParcelDetailViewModel();
        ViewModel.AltOwnership = new List<OwnerShipViewModel>();
        ViewModel.Buildings = new List<BuildingViewModel>();

        AutoMapper.Mapper.Map(result, ViewModel);
        AutoMapper.Mapper.Map<IEnumerable<AltOwnership>, IEnumerable<OwnerShipViewModel>>(AltOwners,ViewModel.AltOwnership);
        AutoMapper.Mapper.Map<IEnumerable<Building>, IEnumerable<BuildingViewModel>>(Buildings, ViewModel.Buildings);
        ViewModel.Pool = _service.HasPool(ParcelId);
        ViewModel.Homestead = _service.IsHomestead(ParcelId);

        return View(ViewModel);
    }

public class ParcelDetailViewModel
    {
        public IEnumerable<OwnerShipViewModel> AltOwnership { get; set; }
        //public IEnumerable<ValueViewModel> Values { get; set; }
        public IEnumerable<BuildingViewModel> Buildings { get; set; }
        //public IEnumerable<TransferViewModel> Transfers { get; set; }
        //public IEnumerable<SiteAddressViewModel> SiteAddresses { get; set; }

        public string ParcelID { get; set; }
        //public string ParcelDescription { get; set; }
        //public int LandArea { get; set; }
        //public string Incorporation { get; set; }
        //public string SubdivisionCode {get;set;}
        public string UseCode { get; set; }
        //public string SecTwpRge { get; set; }
        //public string Census { get; set; }
        //public string Zoning { get; set; }
        public Boolean  Homestead {get;set;}

        //public int TotalBuildingArea { get; set; }
        //public int TotalLivingArea { get; set; }
        //public int LivingUnits { get; set; }
        //public int Beds { get; set; }
        //public decimal Baths { get; set; }
        public short Pool { get; set; }
        //public int YearBuilt { get; set; }
        
    }
  • 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-30T23:06:45+00:00Added an answer on May 30, 2026 at 11:06 pm

    My understanding is that the view model is meant for display ready data. I think the real problem here is putting model dependent logic into the view.

    You can do your service lookup but keep that code in the controller. The view model should be considered display ready (save for some formatting).

    class BuildingViewModel 
    { 
        public string BuildingTypeCode { get;set;}   
        ...other properties 
    } 
    

    and then do the lookup before you render:

    public ActionResult Building()
    {
        var typeCode = // get from original source?
        var model = new BuildingViewModel
        {
            BuildingTypeCode = MyService.GetDescription(typeCode)
        };
        return View("Building", model);
    }
    

    Having come from a long line of JSP custom tags I dread having any code hidden in the view layout. IMO, that layer should be as dumb as possible.

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

Sidebar

Related Questions

I'm building an application against a legacy database that stores lookup values in a
I have a mysql database table that will store locations for buildings and events
I'm building a routine that creates a settings.ini file from a database table. I
I'm building a database for making hotel reservations. One table called reservations holds the
I'm building a Useful Links database for a Classic ASP site. The table has
Scenario I am building a database that contains a series of different tables. These
I have a database table that i want to allow my friends to update.
We are currently building a PostgreSQL database that allows us to create profiles for
I am building a system that stores articles and tags that categorize the article.
I'm building an application that stores lots of data per user (possibly in gigabytes).

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.