vendredi 5 juin 2015

Mvc: Alternative for form collection to better handle huge amount of parameters

I have a form that has just 3 fields and I am writing this to a database by passing the values using a form collection to the business layer.

Assuming I have 35 fields on my form and wants to write this to the database. Is there a better way of doing this than listing 35 fields in my code. I want to reduce the amount of code I write.

    Public ActionResult Create(FormCollection objFrmCollect)
      Employee employee = new Employee();
      employee.Name = objFrmCollect["Name"];
      employee.Gender = objFrmCollect["Gender"];
      employee.City = objFrmCollect["City"];

      EmployeeBusinessLayer empBus = new EmployeeBusinessLayer();

      return RedirectToAction("Index");


Aucun commentaire:

Enregistrer un commentaire