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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:00:28+00:00 2026-06-04T09:00:28+00:00

Trying to rephrase/clean up question here: I’m trying to do some sort of conditional

  • 0

Trying to rephrase/clean up question here:

I’m trying to do some sort of conditional statement to calculate a value. To mock my data I am assigning the value in my controller (temporarily) to see how my UI is coming along. I can perform the calculation in a function block in the view, but it’s lengthy and doesn’t belong there. So, I am trying now to do the calculation in a model (Calculations.cs).

The code for the calculation is working in that a value is being passed, except that my condition is failing and passing the default value of 0 when it should be passing another value based on my mocked value in the controller.

Here is the Calculations.cs

public class Calculations
{
    PriceQuote price = new PriceQuote();
    StepFilingInformation filing = new StepFilingInformation();
    public decimal Chapter7Calculation
    {
        get
        {
            return
                price.priceChapter7
                +
                ((filing.PaymentPlanRadioButton ==
                    Models.StepFilingInformation.PaymentPlan.Yes)
                ?
                price.pricePaymentPlanChapter7
                :
                0);
        }

    }
}

I originally had (filing.PaymentPlanRadioButton == Models.StepFilingInformation.PaymentPlan.Yes) checking whether or not the radio button was set to “Yes”, but changed it to ReferenceEquals. This doesn’t affect the outcome.

I have my controller assigning the value to PaymentPlanRadioButton to “Yes”, so pricePaymentPlanChapter7 should be the value being added to priceChapter7, but it is not. Instead “0” is being added as the fall back to the condition. So PaymentPlanRadioButton is null even though I am assigning it in the controller.

I cannot figure out how to fix this. If I assign it in the model and get it to work that will not resolve the issue as when I remove the mocking controller and expect a user to choose a radio button it will still be null and the condition will fail.

Here is the “mock” controller:

public class QuoteMailerController : Controller
{
    public ActionResult EMailQuote()
    {
        Calculations calc = new Calculations();
        var total = calc.Chapter7Calculation;

        QuoteData quoteData = new QuoteData
        {
            StepFilingInformation = new Models.StepFilingInformation
            {
                //"No" is commented out, so "Yes" is assigned
                //PaymentPlanRadioButton = 
                    //Models.StepFilingInformation.PaymentPlan.No,
                PaymentPlanRadioButton = 
                    Models.StepFilingInformation.PaymentPlan.Yes,
            }
         };
    }
}

And this is where I store prices (PriceQuote.cs):

public class PriceQuote
{
    public decimal priceChapter7 { get { return 799; } }
    public decimal pricePaymentPlanChapter7 { get { return 100; } }
}

This is my ViewModel:

public class QuoteData
{
    public PriceQuote priceQuote;
    public Calculations calculations;
    public StepFilingInformation stepFilingInformation { get; set; }
    public QuoteData()
    {
        PriceQuote = new PriceQuote();
        Calculations = new Calculations();
    }
}

So, the way this should work is 799 + 100 = 899, since PaymentPlan.Yes is assigned as the value to the radio button in the controller. But instead I am getting just 799 (799 + 0) because when I debug PaymentPlanRadioButton is coming up null.

Any thoughts/guidance?

Just in case, here is the PaymentPlanRadioButton located within StepFilingInformation.cs (and is one of my models):

public enum PaymentPlan
{
    No,
    Yes
}
public class PaymentPlanSelectorAttribute : SelectorAttribute
{
    public override IEnumerable<SelectListItem> GetItems()
    {
        return Selector.GetItemsFromEnum<PaymentPlan>();
    }
}       
[PaymentPlanSelector(BulkSelectionThreshold = 3)]
public PaymentPlan? PaymentPlanRadioButton { get; set; }

Sorry for the length.

FOR CONTEXT THIS IS WHAT I WAS TRYING TO GET OUT OF DOING

I originally had this calculation code in a function block in my view. The calculation works fine there, but obviously very lengthy and not appropriate.

This is what my function block looked like (partially)

@{ Model.PriceQuote.calculationChapter7
    =
    Model.PriceQuote.priceChapter7
    +
    ((Model.StepFilingInformation.PaymentPlanRadioButton == 
        StepFilingInformation.PaymentPlan.No)
    ?
    Model.PriceQuote.priceNoPaymentPlan
    :
    Model.PriceQuote.pricePaymentPlanChapter7)
    +
    ...//more of the same
    ;
}

So I’ve been struggling to get this into a .cs file.

  • 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-06-04T09:00:30+00:00Added an answer on June 4, 2026 at 9:00 am

    [Adding a 2nd answer since the added code has changed significantly since the original post].

    I think the root problem here is the way you have implemented your Calculations class. The Chapter7Calculation property is always going to return 799 + 0, because it is using private local class variables to determine what values to return;

    public class Calculations
    {
        PriceQuote price = new PriceQuote();
    
        // private local variable - will ALWAYS have PaymentPlanRadioButton = null
        StepFilingInformation filing = new StepFilingInformation();
    
        public decimal Chapter7Calculation
        {
            get {
                return
                    price.priceChapter7
                    +
                    (filing.PaymentPlanRadioButton == Models.StepFilingInformation.PaymentPlan.Yes)
                    ? price.pricePaymentPlanChapter7
                    : 0);
            }
        }
    }
    

    You have a ‘controller’ modifying some other instance of StepFilingInformation, which your Calculations class has no awareness of. As well, your PriceQuote class is just returning constant or static values, so there’s no real need to instantiate it. Modify that class like so;

    public static class PriceQuote
    {
        public static decimal PriceChapter7 { get { return 799; } }
        public static decimal PricePaymentPlanChapter7 { get { return 100; } }
    }
    

    Change your Calculations to a method like so;

    public decimal CalculatePrice(QuoteData quoteData)
    {
        return PriceQuote.PriceChapter7 + 
            (quoteData.StepFilingInformation.PaymentPlanRadioButton == Models.StepFilingInformation.PaymentPlan.Yes) 
            ? PriceQuote.PricePaymentPlanChapter7 : 0);
    }
    

    And now your controller can pass in the QuoteData instance it has created, and you should see a better result. Example code for the mock controller;

    public class QuoteMailerController : Controller 
    {
        public ActionResult EMailQuote()
        {
            Calculations calc = new Calculations();
    
            QuoteData quoteData = new QuoteData
            {
                StepFilingInformation = new Models.StepFilingInformation
                {
                    PaymentPlanRadioButton = Models.StepFilingInformation.PaymentPlan.Yes,
                }
             };
    
             var total = calc.CalculatePrice(quoteData);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to rephrase my question, cause my last one wasn't clear to everyone.
I think I am been misunderstood here so I will rephrase my question. THE
Trying to comply with StackOverflow's suggestion of asking a question, not creating a discussion,
Trying to parse an HTML document and extract some elements (any links to text
Trying to avoid the SomethingManager trap here... Let's say I'm going to write a
Trying to use GnuPG with Delphi (Win32). I need to sign some file with
Trying to get comfortable with jQuery and I have encountered some sample code that
To Rephrase I am newbie to haskell. I am trying to parse a pcap
Trying to pull a value from the sunrise element from [yweather:astronomy] in the Yahoo
Trying to find some information on this but am unable to get any results

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.