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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:55:08+00:00 2026-05-17T19:55:08+00:00

OK, I have a problem where my calculation never takes place, like it is

  • 0

OK, I have a problem where my calculation never takes place, like it is supposed to. i’m trying to make a computation which solves for the roots of a quadratic equation using the quadratic formula, based on the values of a, b and c entered in a primitive form.

Now, let me supply the code for my Model, view and Controller for this application:

Model:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace RootFinder.Models
{
    public class QuadCalc
    {
        public double quadraticAValue { get; set; }
        public double quadraticBValue { get; set; }
        public double quadraticCValue { get; set; }
        public double x1 { get; set; }
        public double x2 { get; set; }

        public void QuadCalculate(out double x1, out double x2)
        {
            //Quadratic Formula: x = (-b +- sqrt(b^2 - 4ac)) / 2a

            //Calculate the inside of the square root
            double insideSquareRoot = (quadraticBValue * quadraticBValue) - 4 * quadraticAValue * quadraticCValue;

            if (insideSquareRoot < 0)
            {
                //There is no solution
                x1 = double.NaN;
                x2 = double.NaN;
            }
            else
            {
                //Compute the value of each x
                //if there is only one solution, both x's will be the same
                double sqrt = Math.Sqrt(insideSquareRoot);
                x1 = (-quadraticBValue + sqrt) / (2 * quadraticAValue);
                x2 = (-quadraticBValue - sqrt) / (2 * quadraticAValue);
            }
        }
    }
}

View:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Polynomial Root Finder - Quadratic
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>Quadratic</h2>

    <% using(Html.BeginForm("Quadratic", "Calculate")) %>
    <% { %>
    <div>
        a: <%= Html.TextBox("quadraticAValue") %>
        <br />
        b: <%= Html.TextBox("quadraticBValue") %>
        <br />
        c: <%= Html.TextBox("quadraticCValue") %>
        <br />
        <input type="submit" id="quadraticSubmitButton" value="Calculate!" />
        <br />
        <p><%= ViewData["Root1"] %></p>
        <p><%= ViewData["Root2"] %></p>
    </div>
    <% } %>
</asp:Content>

Controller:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RootFinder.Models;

namespace RootFinder.Controllers
{
    public class CalculateController : Controller
    {
        //
        // GET: /Calculate/

        public ActionResult Index()
        {
            return View();
        }

        [AcceptVerbs(HttpVerbs.Get)]
        public ViewResult Quadratic()
        {
            ViewData["Root1"] = "";
            ViewData["Root2"] = "";
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ViewResult Quadratic(QuadCalc newQuadCalc)
        {
            ViewData["Root1"] = newQuadCalc.x1;
            ViewData["Root2"] = newQuadCalc.x2;
            return View();
        }

        public ActionResult Quartic()
        {
            return View();
        }

        public object x1 { get; set; }

        public object x2 { get; set; }
    }
}

Now, I’m trying to still work this out, but I believe the problem may lie in the assigning of the inputted values from the form, into a new object for computation. This could also be a problem considering that MVC will probably take in the form input a string stype, instead of a double, where in my model, I perform computations based off of the input being a double type.

I do not know where to make the string to double conversion if this even is necessary however.

Does anyone see why there is a problem.

The page outputs the following:

x1 = 0
x2 = 0
  • 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-17T19:55:08+00:00Added an answer on May 17, 2026 at 7:55 pm

    You never call the QuadCalculate method.

    Beside of this I would suggest to move out the QuadCalculate from the view model. This latest advice does not affect in any way the actual answer. It’s just a respectful way of implementing the MVC pattern.

    For example:

    Your model class

    public class QuadCalc {
        public double quadraticAValue { get; set; }
        public double quadraticBValue { get; set; }
        public double quadraticCValue { get; set; }
        public double x1 { get; set; }
        public double x2 { get; set; }
    }
    

    and your controller methods

    [AcceptVerbs(HttpVerbs.Post)]
    public ViewResult Quadratic(QuadCalc newQuadCalc) {
        // move your calculation method here or, better,
        // to a class that implements the repository pattern
        // do the calculation and then set the x1 and x2 members of 
        // your model class
        // You dont even need to use ViewData for this, just return 
        // back your model class to your view
        return View( newQuadCalc );
    }
    

    You can then transform your view in a strong-typed view and use your model class inside it

    <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<RootFinder.Models.QuadCalc>" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Polynomial Root Finder - Quadratic
    </asp:Content>
    
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        <h2>Quadratic</h2>
    
        <% using(Html.BeginForm("Quadratic", "Calculate")) %>
        <% { %>
        <div>
            a: <%= Html.TextBox(Model.quadraticAValue) %>
            <br />
            b: <%= Html.TextBox(Model.quadraticBValue) %>
            <br />
            c: <%= Html.TextBox(Model.quadraticCValue) %>
            <br />
            <input type="submit" id="quadraticSubmitButton" value="Calculate!" />
            <br />
            <p><%= Model.x1 %></p>
            <p><%= Model.x2 %></p>
        </div>
        <% } %>
    </asp:Content>
    

    Less magic strings, if you change a property name you can get a compile time error (if you enable view compilation), cleaner code and many other advantage are just waiting for you! 🙂

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

Sidebar

Related Questions

I have a snippet to create a 'Like' button for our news site: <iframe
I have a login.jsp page which contains a login form. Once logged in the
i have a input tag which is non editable, but some times i need
I have a project that adds elements to an AutoCad drawing. I noticed that
I have a script that appends some rows to a table. One of the
I have a new web app that is packaged as a WAR as part
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
I have found this example on StackOverflow: var people = new List<Person> { new
Let say I have the following desire, to simplify the IConvertible's to allow me
I want to have generalised email templates. Currently I have multiple email templates with

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.