How can I access formcollection values in action method through ASP.NET mvc ?

Total Post:149

Points:1043
 814  View(s)
Ratings:
Rate this:

hello!

I have formcollection accessed in action method, but not getting the value of it .

I have written the following code:

 

string value = collection[1];

 

But I am unable get the value.

Help me, how can I access the value in action method.

I want to access form value using form collection

 

  1. Post:52

    Points:366
    Re: How can I access formcollection values in action method through ASP.NET mvc ?

    view code

    <div>
            @using (Html.BeginForm("SignUp","Home",FormMethod.Post))
            {
            <fieldset>
                <legend>
                    Registration
     
                </legend>
                Name:@Html.TextBox("t1")
                    Address:@Html.TextBox("t2")
                    Email:@Html.TextBox("t3")
                <input type="submit" text="Submit" />
            </fieldset>
            }
        </div>

       controller code

    You can access values like this 

           [HttpPost]
            public ActionResult SignUp(FormCollection form)
            {
                string name = form["t1"];
                string address = form["t2"];
                string Email = form["t3"];
                return View();
            }

     

      Modified On Apr-11-2018 11:01:05 PM
  1. Post:149

    Points:1043
    Re: How can I access formcollection values in action method through ASP.NET mvc ?

    Thanks Manish...


    It solved my problem in accessing the value in action method.. It really helped me a lot...

      Modified On Apr-11-2018 11:00:31 PM

Answer