Introduction
In this article we post data from a view to a controller using a form and get the data using a request object.
To post data from a view to a controller, we saw the following methods:
- Using Html.BeginForm() View To Controller Method 1
- Using Html.BeginForm() by passing action name and controller name explicitly View To Controller Method 2
- Using Html.BeginForm() by passing FormMethod View To Controller Method 3
- Using Html.BeginForm() by calling action method by action name View To Controller Method 4
- Using Html.BeginForm() and request object View To Controller Method 5
Step 1
Create a MVC project from the "Empty" template. Right-click on "Controllers" and select "Add" >> "Controller...".
Step 2
Select "MVC 5 Controller - Empty" to add an empty controller. Click on the "Add" button.
Step 3
Name the controller "CalcController". The Index() action result method will be added.
Step 4
To add a view, right-click on "Index" and select "Add View...".
Step 5
Name the view and select "Empty (without model)" as the template. Click on the "Add" button.
Step 6
Here we use the HTML <form> element on the page, not a form with runat=server. The action attribute of the form element is set to post data to the add action method of the Calc controller. When we press the submit button, the post will be done. Once it is submitted, from the controller end we get data from the request.
Step 7
In the following code snippet, we get the value of text1 and text2 using the request object. We do an addition operation and store the result in viewdata. Then the add action method returns the view "Index". Finally we render the result inside the form using viewdata. 
Step 8
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 sum of the two values.

<< View to Controller Method 5: Day 20 View to Controller Method 7: Day 22 >>

Lalit RaghavPosted Jul 17, 2015, 8:30 AM
Sir can you tell us .what is difference between these all method and which method we should use which condition
Akshay PatelPosted Sep 30, 2014, 9:06 AM
Pleases refer my previous article - http://www.c-sharpcorner.com/UploadFile/db2972/view-to-controller-method-5-day-20/
chandra varmaPosted Sep 30, 2014, 4:12 AM
hi akshay,Nice article, i have a small doubt on the above the article ,we are using html form ,but if we want to pass data to the action method in another controller (in this article we are passing the data in the same controller(calc)).i am not getting any intellisence for mentioning controller name in index.cshtml.please let me know the solution
Guest UserPosted Sep 9, 2014, 10:03 AM
hey Akshay, you're becoming expert in MVC by writing so much on it. Great!