Rustovich
Rustovich

Reputation: 191

Generic object controller in MVC, can you improve my code?

I am creating an application that will display a list of objects in a datagrid (list of any type of object), and allow the user to update any item. The code will know nothing about the object being displayed until runtime. Can you improve my code for the update? I am using Formcollection to get items from the form and creating an instance of my class based on the Routing info, ie it will pull out the object (hardcoded Employee for this example) from URL and create an instance of it.

[HttpPost]
public ActionResult Details(FormCollection Collection)    
{
             try
            {
                foreach (var item in Collection)
                {
                   //TODO set up form values container for populating new object 
                   string test = Collection[item.ToString()];
                 }
                 Assembly CurrentAssembly =
                 Assembly.GetExecutingAssembly();
                dynamic updateObject = CurrentAssembly.CreateInstance("Employee");

Upvotes: 0

Views: 425

Answers (1)

Mathias F
Mathias F

Reputation: 15891

Have a look at ModelVisualizer in MVCContrib. It can display a collection of objects. You could start from there.

Upvotes: 1

Related Questions