1

我正在努力通过来自 kendo ui 网格的 WCF 服务调用创建操作。当 odataservice 调用业务逻辑控制器写入记录时,它传递了一个空引用....客户对象被填充,直到调用业务逻辑 CreateEntity 方法。我最初认为这是因为内容类型,但我现在有疑问。使用 fiddler 直接访问 WCF 服务成功创建记录...

剑道网格:

这是剑道网格调用的应用程序级别 Customer_Create 操作

@(Html.Kendo().Grid<Application.ServiceProxy.CustomerDTO>()
.Name("grid")
.Columns(columns =>
{

    columns.Bound(c => c.salesOrganizationID).Width(15).Title("sales org");
    columns.Bound(c => c.customerID).Width(20).Groupable(false);
    columns.Bound(c => c.name1).Width(25).Title("name");
    columns.Bound(c => c.city).Width(15).Title("city");
    columns.Bound(c => c.stateCode).Width(10).Title("state");
    columns.Bound(c => c.countryCode).Width(15).Title("country");
    columns.Bound(c => c.matchcode).Width(25).Title("matchcode");
    columns.Command(command => { command.Edit(); command.Destroy(); }).Width(35);
    //Add program type here CMI, VMI etc..        
    //columns.Width(25).Title("program");  

})
.ToolBar(toolbar => toolbar.Create())
.Editable(ed => ed.Mode(GridEditMode.PopUp).Window(w => w.Title("Edit Customer Details").Name("editWindow").HtmlAttributes(new { @style = "width:700px;" })))
.Pageable()
.Sortable()
.Groupable()
.Scrollable()
.Filterable()
.HtmlAttributes(new { style = "height:420px;" })
.DataSource(dataSource => dataSource
    .Ajax()
    .PageSize(20)
    .ServerOperation(true)
    .Events(events => events.Error("error_handler"))
    .Model(model => model.Id(c => c.customerID))
    .Create(update => update.Action("Customer_Create", "Customer"))
    .Read(read => read.Action("Customer_Read", "Customer"))
    .Update(update => update.Action("Customer_Update", "Customer"))
    .Destroy(update => update.Action("Customer_Delete", "Customer"))


)

)

这是剑道网格调用的应用程序级别 Customer_Create 操作

     [System.Web.Http.HttpPost]
            public ActionResult Customer_Create([DataSourceRequest] DataSourceRequest request, Application.ServiceProxy.CustomerDTO customer)
    {

        if (customer != null && ModelState.IsValid)
        {
            var odataService = new Container(new Uri("http://localhost:8089/odata/"));
            //odataService.r
             odataService.AddToCustomer(customer);
            odataService.SaveChanges();

            return Json(ModelState.ToDataSourceResult());

        }
        return View("Index");
    }

这是通过生成的 WCF 数据服务调用的 CreateEntity 方法。

        protected override CustomerDTO CreateEntity(CustomerDTO customerDTO)
    {

        var customer = new customer()
        {
            matchcode = customerDTO.matchcode,
            salesOrganizationID = customerDTO.salesOrganizationID,
            statusID = customerDTO.statusID,
            serviceLevelStatusID = customerDTO.serviceLevelStatusID,
            mediaIDLogo = customerDTO.mediaIDLogo,
            systemID = customerDTO.systemID,
            customerExternalSystemID = customerDTO.customerExternalSystemID,
            internationalGroup = customerDTO.internationalGroup,
            division = customerDTO.division,
            corporateID = customerDTO.corporateID,
            inventoryManagerID = customerDTO.inventoryManagerID,
            dunsNumber = customerDTO.dunsNumber
        };

        entity.customer.Add(customer);
        entity.SaveChanges();

        return GetEntityByKey(customer.customerID);
    }
4

0 回答 0