-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[Question] ModelBinding and consecutive integers #5679
Comments
Model binder is already able to handle not consecutive indexes. See http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/ |
Thanks @frankabbruzzese I will look into that! |
@frankabbruzzese Do you have an example to override the whole process? Ideally I would like to generate Perhaps something like // Signature example (can't recall paramers exactly for existing)
public static IHtmlContent EditorFor<TModel>(..., Func<TModel, string> indexId)
{
// Generates <input type="hidden" name="Index" value="@indexId()" />
}
// Usage
@for(var i = 0; i < Model.Items.Count; ++i)
{
@Html.EditorFor(_ => Model.Items[i], "Template", model => mode.Id or _ => Guid.NewGuid())
} |
You may use Guids! This is the best way to do it. I do the same! |
Found it rather hard to find the pieces that are related :) Hopefully I'll have time this weekend to put togheter extensions methods that sit ontop of existing
|
@joacar, the part of the code dealing with Guids is the ServerCrudController<T, T1, K>, since all grid operations of the server grid are performed through ajax with the help of descendants of this generic controller. Pay attention, there are 2 ways to create a new row one for the batch grid(the one you are interested in) where the guid is packaged like |
We are closing this issue because no further action is planned for this issue. If you still have any issues or questions, please log a new issue with any additional details that you have. |
Hi,
I generate some models dynamically on the client-side and sends a request the a controller to "inflate" the editor template which is then appended the the DOM.
After appending the resulted template (or one has been deleted) I need to ensure that all models are in consecutive order with respect to name and id html attributes.
Is there any way to manipulate the model binding to accept none-consecutive or perhaps just use another identifier. Perhaps this is more difficult since probbly both model binding and name/id generation is affected.
Thanks!
#5642
The text was updated successfully, but these errors were encountered: