Hello,
I'm using MVC 5 + Knockoutjs.
I've a table named by ProductCategories, this one has a column named by Type (Int16). My enum define the value that column.
Now I need to create a custom column and it is necessary has a filter column, but I don't know how can I do that, because the information that show is a String (data annotation from enum) and my database has a Int16 column.
I tried to do, but doesn't work. When I perform a filter happen an exception.
Error:
{"Identifier 'TypeName' is not a parameter or variable or field of 'Sight.NoAlvo.TO.Entity.BasicForm.ProductCategory.ProductCategory'. If 'TypeName' is a property please add the FieldAlias or Storage attribute to it or declare it as a field's alias."}
My solution:
Entity
public class ProductCategory : BaseEntity
{
#region .: Properties :.
[DataMember]
public Int64 Id { get; set; }
[DataMember]
public String Name { get; set; }
[DataMember]
public Double MinimalValue { get; set; }
[DataMember]
public Int16 Type { get; set; }
[IgnoreDataMember]
public String TypeName { get
{
return ((EnumCategoryType)this.Type).GetNameIdentifier();
}
}
}
Controller
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult KODataSource(DataManager clsDataManager)
{
BaseResult<ProductCategory> clsData = ProductCategoryBusiness.GetAll(clsDataManager);
ResultModel result = new ResultModel();
result.result = clsData.Result;
result.count = clsData.Count;
return Json(result, JsonRequestBehavior.AllowGet);
}
View
$(function () {
window.baseView = {
dataSource: ej.DataManager({ url: '@Url.Action("KODataSource")', adaptor: "UrlAdaptor" }),
column: [
{ headerText: "Ações", template: true, templateID: '#CustomCommand', width: '10%' },
{ field: "Name", headerText: "Nome" },
{ field: "MinimalValue", headerText: "Valor mínimo", format: "R$ {0:n}" },
{ field: "TypeName", headerText: "Tipo de Categoria" }, ]
};
ko.applyBindings(baseView);
});
Thank you.
Attachment:
error_3dd33906.zip