This question is locked. New answers and comments are not allowed.
Hi,
Im developing an application using ASP.MVC, Kendo and OpenAccess.
After created a custom property for an specific entity, I'm trying unsuccessfully to bind it to my Datasource and Grid.
Partial Class
Service
View
Controller
Im developing an application using ASP.MVC, Kendo and OpenAccess.
After created a custom property for an specific entity, I'm trying unsuccessfully to bind it to my Datasource and Grid.
Partial Class
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
namespace
ErpMvc.OpenAccess
{
public
partial
class
Customer
{
public
string
CustomProperty
{
get
{
return
"My Custom Property Text"
;
}
}
}
}
Service
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.Mvc;
using
ErpMvc.OpenAccess;
using
Kendo.Mvc.Extensions;
using
Kendo.Mvc.UI;
namespace
ErpMvc.Services
{
public
class
CustomerService
{
public
static
IEnumerable<Customer> GetCustomers()
{
var dbContext =
new
EntitiesModel();
return
dbContext.Customers.Select(customer =>
new
Customer
{
CustomerID = customer.CustomerID,
FirstName = customer.FirstName,
CustomProperty = customer.CustomProperty
});
}
}
}
View
@model IEnumerable<ErpMvc.OpenAccess.Customer>
@{
ViewBag.Title =
"Index"
;
Layout =
"~/Views/Shared/_Layout.cshtml"
;
}
@(Html.Kendo().Grid(Model)
.Name(
"Customers"
)
.Columns(columns =>
{
columns.Bound(c => c.FirstName).Title(
"First Name"
);
columns.Bound(c => c.CustomProperty).Title(
"Custom Property"
);
})
.Pageable()
.Sortable()
.Editable(editable => editable.Mode(GridEditMode.InLine))
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(customerID => customerID.CustomerID))
.Read(read => read.Action(
"Customers_Read"
,
"Customer"
))
.Update(update => update.Action(
"Customers_Update"
,
"Customer"
))
.PageSize(50)
)
)
Controller
public
ActionResult Customers_Read([DataSourceRequest] DataSourceRequest request)
{
return
Json(CustomerService.GetCustomers().ToDataSourceResult(request));
}
Error messages I'm getting from VS
- Property or indexer 'CustomProperty' cannot be assigned to -- it is read only
After defined a "set{}" on my CustomProperty, this error messages was resolved but I started get this other one
- (...) If 'CustomProperty' is a property please add the FieldAlias or Storage attribute to it or declare it as a field's alias.