I am trying to set a Profile Property (ComplexID) through the standard Account controller code that comes with the standard MVC3 template. I am using a autocomplete widget from the jquery library to set the value of a hidden field when a value is selected from the autocomplete. The setter is confirmed by an alert I added, but when I try to save the textbox values, I get an error from the Model.IsValid saying the the ComplexID needs to be set. In the Account Model, I have set the ComplexID field as [Required]. What am I doing wrong? Thanks
<div>
<input type="text" name="q" id="complexes" />
@Html.HiddenFor(m => m.ComplexID, new { id="complexid"})
</div>
and the Jscript is:
$("#complexes").autocomplete({
source: function(request, response) {
$.ajax({
url: "/Account/QuickSearch", type: "POST", dataType: "json",
data: { query: request.term },
success: function(data) {
response($.map(data, function(item) {
return { label: item.Name + " , " + item.Address1, value: item.Name, id: item.ComplexID };
}))
}
})
},
minLength: 3,
select: function(event, ui) {
var selecteditem = ui.item;
$("#complexid").text(selecteditem.id);
alert(ui.item ? ("You picked '" + selecteditem.label + "' and the hidden textbox now has a value of " + $("#complexid").text()) : "Nothing selected");
}
});
Change this:
on