I'm implementing multiselect checkboxes using the following code:
<input type="checkbox" name="Location" value="S" /> S
<input type="checkbox" name="Location" value="I" /> I
<input type="checkbox" name="Location" value="T" /> T
@Html.HiddenFor(model => model.Location)
I have some jQuery to pull the values:
$("#Location").change(function () {
// grab the selected options
var grid = $.map($("input[name='Location']:checked"), function (e, i) {
return e.value;
});
$("#Location").val(grid);
console.log("Location: " + $("#Location").val());
});
The console outputs what I would expect, for example:
Location: S,I,T
if all checkboxes are checked. For some reason though when the data is saved into the database only the first letter is being saved. The database field is nvarchar(6) so it's not that it's being truncated at that end. Any ideas why the full value of the string is not being passed?
Aucun commentaire:
Enregistrer un commentaire