This question is locked. New answers and comments are not allowed.
Hello!
Using a EditorTemplate in concert with the Grid made me run into trouble.
The template:
Simple enough. Essentially, a stripped down version of what MVC scaffolds for you.
But wait, this gets generated:
The thing gets wrapped into a form-tag and some buttons are appended too, that's ok and necessary and I understand that, but woah, why is there suddenly another Input-Tag for the Id field? Of course this will blow up in your face, since there are now two fields with the same name, which both can cause problems on the client and server-side.
Looks like the Grid appends a hidden field for each DataKey, so I guess this is intended behaviour, and even makes sense, somewhat.
My complaint with that is, that you have to remove your own HiddenFor, so it doesn't conflict with the one generated by the Grid, which reduces reusabilty of the template, since without an Id it's pretty much useless everywhere else. Couldn't you check if there already lingers a field for the DataKey around somewhere and then don't append yours? Or is there any other way to turn off this behaviour?
Using a EditorTemplate in concert with the Grid made me run into trouble.
The template:
@model Sardegna.Ali.WebUI.Models.CostCategoryViewModel@Html.ValidationSummary(true, Resources.ErrorMessages.ErrorsOccured)<fieldset> <legend>Kostenkategorie</legend> @Html.HiddenFor(model => model.Id) @Html.HiddenFor(model => model.Version) <div class="editor-label"> @Html.LabelFor(model => model.Name) </div>
(...)</fieldset>Simple enough. Essentially, a stripped down version of what MVC scaffolds for you.
But wait, this gets generated:
<fieldset> <legend>Kostenkategorie</legend> <input data-val="true" data-val-number="The field Id must be a number." data-val-required="Das Feld "Id" ist erforderlich." id="Id" name="Id" type="hidden" value="3"> <input id="Version" name="Version" type="hidden" value="AAAAAAAAAL4="> <div class="editor-label"> <label for="Name">Bezeichnung</label> </div>
(...)
</fieldset><input name="Id" type="hidden" value="3"><button class="t-button t-button-icon t-grid-update" type="submit"><span class="t-icon t-update"></span></button><a class="t-button t-button-icon t-grid-cancel" href="/ALI/CostCategory"><span class="t-icon t-cancel"></span></a></div>The thing gets wrapped into a form-tag and some buttons are appended too, that's ok and necessary and I understand that, but woah, why is there suddenly another Input-Tag for the Id field? Of course this will blow up in your face, since there are now two fields with the same name, which both can cause problems on the client and server-side.
Looks like the Grid appends a hidden field for each DataKey, so I guess this is intended behaviour, and even makes sense, somewhat.
My complaint with that is, that you have to remove your own HiddenFor, so it doesn't conflict with the one generated by the Grid, which reduces reusabilty of the template, since without an Id it's pretty much useless everywhere else. Couldn't you check if there already lingers a field for the DataKey around somewhere and then don't append yours? Or is there any other way to turn off this behaviour?