Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC3
hi,
how to pass data from one view to controller in mvc3
Posted 29-Dec-11 4:02am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
@using(Html.BeginForm("actionName","ControllerName",FormMethod.Post))
{
      @Html.Editor("Key","Value")
} 

In Controller
[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.
  Permalink  
v2

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

  Print Answers RSS
0 Maciej Los 230
1 OriginalGriff 202
2 Richard MacCutchan 185
3 Tomas Takac 146
4 CPallini 125
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 12 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100