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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:20:18+00:00 2026-05-28T03:20:18+00:00

There is a field in our database which really ought to be a boolean,

  • 0

There is a field in our database which really ought to be a boolean, but for some reason the original developers made it a CHAR which will either be set to “1” or “0”.

    [Column("CHARGEABLE")]
    [StringLength(1)]
    private string Chargeable { get; set; }

I want my model to represent this field as a boolean so I figured I could add a property to my model to wrap it:

    [NotMapped]
    public bool ChargeableTrue
    {
        get
        {
            return Chargeable == "1" ? true : false;
        }
        set
        {
            Chargeable = value ? "1" : "0";
        }
    }

Now on my View I just display the EditorFor ( ChargeableTrue ), but when I click save it doesn’t actually update it.

I think what is happening is that when the model is being updated, it’s still attempting to get the value of ‘Chargeable’ from the View, even though I haven’t displayed it there. And since there is no input field, it just gets null and ends up saving that to the database.

        if (ModelState.IsValid)
        {
            db.Entry(call).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }

What is one expected to do in this situation?

  • 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-28T03:20:19+00:00Added an answer on May 28, 2026 at 3:20 am

    Based on KMan’s answer, here’s the extended version just in case you’re not familiar with creating view models.

    The idea is that your domain object is not really what you want to be updating exactly from your views. Instead, you create a go-between that can also include view-specific items (like a list of objects to populate a drop-down).

    public class MyViewModel {
        public bool Chargeable { get; set; }
    }
    

    Now you can do this:

    @* In view *@
    Html.EditorFor(m => m.Chargeable)
    
    // In controller
    public ActionResult Save(MyViewModel model) {
        if (ModelState.IsValid) {
            var domainObject = new MyObject() {
                Chargeable = model.Chargeable ? "1" : "0"
            };
    
            // the rest of your code using domainObject
        }
    }
    

    I’d consider just creating an overload of your domain object’s constructor that accepts your view model to keep the mapping in one place. I typically use a tool like AutoMapper to map objects or manual extension methods.

    A view model typically contains a sub-set of your domain object’s properties, but can contain all of them or more properties like lists, visbility states, etc. They come in incredibly useful and I’ve never done a MVC project where I haven’t used them.

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

Sidebar

Related Questions

I'm using find_by_sql with Activerecord which I generate another field there that doesn't in
In a database, there is a field that saves a closure date. This date
We have some code in which we need to maintain our own identity (PK)
For our application, which has a website and a backend, we really like the
Is there a field or anyway to retreave the smtp server of a user
Consider i have a registartion table and there is field prefLocationId and it contains
I want to allow users to either have there username field empty at any
There is a field in my company's Contacts table. In that table, there is
There's a field with type of varchar. It actually stores a float point string.
in a form if there is a field and a global error both messages

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.