Feeds:
Posts
Comments

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())
{
@Html.TextBox(“txtCustomerName”)
<input type=”submit” value=”Send” />
}

Code in Controller

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index1(FormCollection collection)
{
string customerName = collection["txtCustomerName"].ToString();
return null;
}

Output :

index

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

1

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 »

Follow

Get every new post delivered to your Inbox.

Join 29 other followers