null pointer
New Member
As per a question that I asked yesterday I was trying to find a way to dynamically create more text boxes and have those map to my view's model so upon post to the server it will grab all the dynamically(js) generated text boxes and post that to an object such as a List.To give an example of this confusing question:I have a textbox that is labeled "Primary Contact" and the ticket creator can enter the contacts name and phone number into this box. What I want to do essentially is, switch this to three text boxes. One for Name, Email and PhoneNumber instead of one box. Then I will create some javascript that will dynamically create three more boxes to add another contact to this List collection. Then when the user submits the form to modify or create the ticket it passes this collection inside the model to the controller. However with petapoco it is a little confusing. Let me show you the controller:\[code\][HttpPost]public ActionResult ModifyTicket(Ticket model){ string userString = User.Identity.Name.Replace("ONHOLD\\", ""); if (ModelState.IsValid) { model.CreatedDate = DateTime.Now; model.LastUpdateBy = Util.GetEmployeeIdByName(userString); model.LastUpdate = DateTime.Now; model.IsComplete = false; model.ClientString = Util.GetClientNameById(model.ClientId); model.LocationString = Util.GetLocationNameById(model.LocationId); model.Update(); SuccessMessage = "You have successfully updated ticket number: " + model.TicketId + " for the following client: " + model.ClientString + "."; return RedirectToAction("Index"); } ErrorMessage = "Woops! Something went wrong, please check back in a few moments, if the problem persists please contact development."; return RedirectToAction("Index");}\[/code\]The simple answer to this would be that my database model would contain a List object for this exact reason. However, I am using PetaPoco and I'm not entirely sure how it would be done. I could manually add in a collection to my Database model but when I regenerate my model based on any database schema changes I will lose any changes I've made to the file. I am also using a partial class that my view uses for validation using DataAnnotations. However this class is identical to the database model it just contains DataAnnotations to provide client-side validation.If anyone understands what I'm trying to accomplish I would be more than happyto provide more information to clarify any missing pieces. I just need a resolution to this as I can't find a solid way to go about resolving this issue!