Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Use of FormCollection in MVC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 554
    Comment on it

    FormCollection class in MVC is used to send or retrieve form data from one view to another.
    Using this you can access every element of your form means all the controls


    Form collection is the collection of all the object that we use in our view so while retrieving any control property we can get it from the FormCollection class.


      /*  To post all the details from the view into the Edit action */

            public ActionResult Edit(FormCollection frmobj)
                Details obj = new Details();
                Database dbobj = new Database();
       /*  To retrieve object values from the view */ 
                obj.Name = frmobj["Name"];
                obj.dob = frmobj["dob"];
                string gethobbies = Convert.ToString(frmobj["chkHobbies"]);
                return View(detail);

    HTTPPost is the way to send data from one view to another and we will access all the elements of the forms by its name.


    In this example the user details like name and date of birth is first posted from the view and then passed into the action and then using the FormCollection class the values is being accessed.

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: