Introduction
In this article we create four forms for addition, subtraction, multiplication and division in the same page.
Procedure
Create an MVC project from the "Empty" template.
Right-click on "Controllers" and select "Add" >> "Controller...".
Select "MVC 5 Controller - Empty" to add an empty controller.
Click on the "Add" button.
Name the controller "CalcController".
The Index() action result method will be added.
To add a view, right-click on "Index" and select "Add View...".
Name the view and select "Empty (without model)" as the template. Click on the "Add" button.
Create the following four form tags.
Addition
Subtraction
Multiplication
Division
Create four action methods for the four operations.
Addition: In this method we get data using the Request.Form collection.
Subtraction: In this method we get data using the Request.Form.Get method.
Multiplication: In this method we get data using the Request.Params indexer.
Division: In this method we get data using the Request object.
We can get posted data using any of the preceding ways for all the operations but we use multiple ways for learning purposes.
Run the project, insert a value for no1 and no2 and click on the "Submit" button. The form will be submitted and we will get the result of the two values.