In my controller, I get a list of brands:
private IEnumerable<Brand> GetBrands()
{
List<Brand> brandList = new List<Brand>();
List<Brand> brands = Brand.GetList();
brands = brands.OrderBy(b => b.BrandCode).ToList();
return brands;
}
I then stuff that list in a ViewBag for my Edit view:
[HttpGet]
public ActionResult Edit(int id)
{
this.ViewBag.BrandList = this.GetBrands();
}
And in my Edit view, I'm trying to implement autocomplete:
<script type="text/javascript">
$(document).ready(function () {
var brandList = @Html.Raw(new JavaScriptSerializer().Serialize(this.ViewBag.BrandList));
$('#BrandCode').autocomplete({
source: brandList,
minLength: 3
});
console.log(brandList);
});
</script>
From the console logging, I see the brandList is a list of Objects:
But I can't get a match in the BrandCode field? What am I doing wrong?
EDIT:
Here is the Brand entity:
public class Brand : PersistantEntity
{
private IBrandRepository repository;
public int Id
{
get { return this.repository.Id; }
set { this.repository.Id = value; }
}
public string BrandCode
{
get { return this.repository.BrandCode; }
set { this.repository.BrandCode = value; }
}
protected override Repository.Abstract.IRepository Repository
{
get { return this.repository; }
set { this.repository = value as IBrandRepository; }
}
public Brand()
{
this.repository = RepositoryFactory.CreateFromConfig<IBrandRepository>();
}
internal Brand(IBrandRepository repository)
{
this.repository = repository;
}
}