Click here to Skip to main content
15,885,027 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hi,
how to pass data from one view to controller in mvc3
Posted

 
Share this answer
 
Hello,

There are number ways available in mvc to pass the data from view to controller. it depends on what's the story on your application means where you want to pass the data in controller ,POST or In GET Method.

In GET Method you can pass the value by calling action using java script or jqury.

I will explain you how to pass value from view to POST Method in controller by using in "FormCollection"

FormCollection is generic collection in which value store in "key-Value" pair. but you can get value from this only on POST Method.

refer following code stuff.

In View
C#
@using(Html.BeginForm("actionName","ControllerName",FormMethod.Post))
{
      @Html.Editor("Key","Value")
} 

In Controller
C#
[HttpPost]
public ActionResult ActionName(FormCollection coll)
{
   string value = coll["Key"];
}


In this way also you can pass the value from view to controller POST Method.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900