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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:25:47+00:00 2026-06-17T18:25:47+00:00

I have 2 methods : Add and Subtract. I want that when clicked Add

  • 0

I have 2 methods : Add and Subtract. I want that when clicked Add button, the 3rd textbox displays the result of A + B; clicked “Subtract” button, the 3rd textbox displays the result of A – B.

I thought it should be a simple thing to do (because it can be done within a few lines of code in ASP.NET WebForm Application). But after trying many times and asked a few of friends, I still cannot find the solution…

@using (Html.BeginForm("Add", "MyMVC"))
{
    <ol>
        <li>
            @Html.TextAreaFor(m => m.A)
        </li>
        <li><span>+ </span></li>
        <li>
            @Html.TextAreaFor(m => m.B)
        </li>
        <li><span>= </span></li>
        <li>
            @Html.TextAreaFor(m => m.C)
        </li>
    </ol>
    @{
    Html.RenderAction("Calculate", "MyMVC");
    }
    @{
    Html.RenderAction("Subtract", "MyMVC");
    }
}
  • 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-17T18:25:49+00:00Added an answer on June 17, 2026 at 6:25 pm

    The RenderAction tags aren’t needed. The BeginForm extension also needs to render a form element that posts to itself.

    Change your view to

    @model SampleMvc.Models.SumModel
    
    @using (Html.BeginForm())
    {
        <ol>
            <li>
                @Html.TextAreaFor(m => m.A)
            </li>
            <li><span>+ </span></li>
            <li>
                @Html.TextAreaFor(m => m.B)
            </li>
            <li><span>= </span></li>
            <li>
                @Html.TextAreaFor(m => m.C)
            </li>
        </ol>
        <input type="submit" id="add" name="Calculate" value="Add" />
        <input type="submit" id="subtract" name="Calculate" value="Subtract" />
    }
    

    Notice the name attribute on the submit inputs, this will enable the default model binder to bind to a property called Calculate.

    For you View model use something similar to

    public class SumModel {
            public int A { get; set; } 
            public int B { get; set; } 
            public int C { get; private set; }
            public string Calculate { get; set; }
    
            public void RunCalculation() {
                if (Calculate.Equals("add",StringComparison.InvariantCultureIgnoreCase)) {
                    C = A + B;
                } else {
                    C = A - B;
                }
            }
        }
    

    Then in the controller have actions similar to:

    public ActionResult Calculate() {
            return View();
        }
    
    [HttpPost]
    public ActionResult Calculate(SumModel sumModel) {
        sumModel.RunCalculation();
    
        return View(sumModel);
    }
    

    When the form is submitted via the click events on the submit inputs the value of the button will be auto-magically bound to the Calculate property of the SumModel.

    Then when the method RunCalculation is called it uses the property to work out which operation to run against the values A and B

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

Sidebar

Related Questions

I have 2 methods that add the Previous, Next & Done toolbar above the
I have to add methods to Class in execution time. class ExtendableClass end The
Let's say I have a simple ASP MVC3 list controller, with an add method,
Greetings, I have a method to capture packets. After capturing I want to add
I have methods in all of my models that look like this: def formatted_start_date
In C# I have methods that use [WebMethod(EnableSession = true)] I consume them in
I have a class that modifies data via some extension methods. In order to
I have this method (Matrix::WriteToArray(double &CopyOfArray)) that I want to write a copy of
PHP's DateTime class has the two methods add() and sub() to add or subtract
I have tried several methods to add an Icon to a JFrame. Every method

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.