INTALLATION NOTES

SERVER SIDE: In your application Global.asax.cs Application Start:

Change the DefaultBinder to MooiNooiModelBinder

protected void Application_Start()
{

RegisterRoutes(RouteTable.Routes);
ModelBinders.Binders.DefaultBinder = new MooiNooiModelBinder(); //JUST ADD THIS LINE
}

CLIENT SIDE

If you have entity A which have a relation 1 ... N with B

A
  • Name
  • Date
  • Bs collection of Bs

B
  • IdB Primary Key
  • Description
  • Owner

The data binder will search every Child Entity using the primarykey value...

So in Modify when you load the entity in your Html if you delete the entity:

Automatically the data binder will delete this entity from the collection. Also if the databinder is not able to locate and ID value in the collection it will add it like new... the same for update, the databinder will search the Id value throught the collection an update the fields....

You only need to work a little with the Jquery to search the next available index in the child property collection and add the three inputs needed...

Cool... isn't it? I didn't work so much with this so I'm sure that it has some bugs... please don't hesitate to contact me if I can help in anything....


Then in your html form should be:

<input type="text" name="a.Name" />
<input type="text" name="a.Date" />

<!-- The collection -->
<
<input type="text" name="Model.Bs0.IdB" value="1" />
<input type="text" name="Model.Bs0.Description" value="Test b" />
<input type="text" name="Model.Bs0.Owner" value="Ricardo Lopez Rey" />

<!-- if you add a new B with jquery in the html form -->
<input type="text" name="Model.Bs1.IdB" value="-1" /> Use negative values for new added entity
<input type="text" name="Model.Bs1.Description" value="Test b" />
<input type="text" name="Model.Bs1.Owner" value="Ricardo Lopez Rey" />

  • It's not important the index only that all the inputs for one B should be the same
  • Use negative number for the primary key value

Last edited Mar 10, 2010 at 12:22 PM by RicardoLopezRey, version 5

Comments

No comments yet.