Posts Tagged ‘MVC4 Razor : How to get the value from view to controller’

MVC4 Razor : How to get the value from view to controller ?

Explanation :

Here i explain how to get the value from html razor control (view) to controller

Code in View:

@using (Html.BeginForm())
<input type=”submit” value=”Send” />

Code in Controller

public ActionResult Index1(FormCollection collection)
string customerName = collection[“txtCustomerName”].ToString();
return null;

Output :


After press send button the value will be catch in controller (as like below)


Note :
As above , we can get value of other control from the view to controller
1. [AcceptVerbs(HttpVerbs.Post)] , will do action when we use Html.BeginForm()
2. FormCollection : It provides to access  the values that were just posted to your page.

Read Full Post »


Get every new post delivered to your Inbox.

Join 29 other followers