Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

I'm wondering if someone can direct me to the best possible way to post data from a repeated form to a controller action. In my project i have the following:

C#
//Model 
Public Class TicketHoder
{

 public string Name {get:set;}
 public string Mobile {get;set;}
}


C#
//Action
 [HttpPost]
public ActionResult SaveDetails(TicketHolder model)
{
  
  // retrieve the posted data here from the repeated form
   return View(model)
}


C#
//View

@using(Html.BeginForm("SaveDetails", "MyController", FormMethod.Post, new {id = "saveForm"}))
{
   for (int i = 0; i < ViewBag.Quantity; i++) 
    {  
       //ViewBag.Quantity is  the number tickets .. so lets say there are 2 tickets
       //so the form repeats twice
     <div>
      <label for="TicketHolder.Name" class="left">Ticket Holder Name<span 
      class="required">*</span></label>
     </div>
     
     <div>
         @Html.TextBoxFor(m => m.TicketHolder.Name, new { maxlength = 25, tabindex = 1 })
    </div>

       <div>
      <label for="TicketHolder.Mobile" class="left">Ticket Holder NU,ber<span 
      class="required">*</span></label>
     </div>
     
     <div>
         @Html.TextBoxFor(m => m.TicketHolder.Mobile, new { maxlength = 25, tabindex = 2 })
    </div>
    

    }
}



How can i go about in achieving this? or is there a better way i go about in achieving this?

Thank you

What I have tried:

Currently when i post the data , the only information that is sent to the controller is for the first form and that it. so i'm stuck and not sure on how i can go about in achieving this.
Posted
Comments
1Future 11-Jan-18 6:14am    
Fantastic!! exactly what i needed! thank you so much
Karthik_Mahalingam 24-Jan-18 9:29am    
welcome
Tip:
use  Reply   button to post comments/query to the concerned user, so that the user gets notified and respond to your text.

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