0

用户放入网格的信息似乎并没有真正传递到模型中(我的理论),null在控制器中返回一个值。我已经尝试了各种小修复,并且已经环顾了很长时间,但是没有经验在这里看到问题。任何人都可以在这里提供任何帮助吗?

看法:

@model Johnson.Billing.Models.TaxService

@using(Html.BeginForm("Save", "TaxService"))
{

<div>
@(Html.Kendo().Grid(Model.Locations)
    .Name("Locations")
    .Columns(columns =>
    {
        columns.Command(command => { command.Destroy(); }).Width(80);
        columns.Bound(o => o.State).Title("State").EditorTemplateName("TaxService");
        columns.Bound(o => o.LocationNum).Title("Loc #");
        columns.Bound(o => o.BasePremium).Title("Base Prem:").Format("{0:c}");
        columns.Bound(o => o.CargoPremium).Title("Cargo Prem:").Format("{0:c}");
        columns.Bound(o => o.InlandMarinePremium).Title("Inland Marine Prem:").Format("{0:c}");
        columns.Bound(o => o.LiabilityPremium).Title("Liability Prem:").Format("{0:c}");
        columns.Bound(o => o.LimitOfLiability).Title("Limit of Liability:").Format("{0:c}");
        columns.Bound(o => o.PropertyContentPremium).Title("Property Content Prem:").Format("{0:c}");
    })
    .ToolBar(toolbar => toolbar.Create().Text("Add a State Tax Calculation"))
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .DataSource(dataSource => dataSource
        .Ajax()
        .ServerOperation(false)
        .Model(model => model.Id(o => o.LocationNum))
        //.Create(update => update.Action("Location_Create", "TaxService"))
))

</div>
<input type="submit" value="Test Taxes" />
}

(create 函数是我最近添加的,但不起作用,所以我现在将其注释掉)

模型:

    public class TaxService
{
    public string DepartmentType { get; set; }
    public DateTime? TransactionDate { get; set; }
    public string TransactionType { get; set; }
    public DateTime? OriginalTransactionDate { get; set; }
    public int PolicyFee { get; set; }
    public int CompanyFee { get; set; }
    public int CompanyID { get; set; }
    public string IncludesWind { get; set; }
    public string CancellationType { get; set; }
    public DateTime? EffectiveDate { get; set; }
    public DateTime? TransactionEffectiveDate { get; set; }
    public List<Location> Locations { get; set; }
}

public class Location
{
    public int LocationNum { get; set; }
    public string State { get; set; }
    public int BasePremium { get; set; }
    public int CargoPremium { get; set; }
    public int InlandMarinePremium { get; set; }
    public int LiabilityPremium { get; set; }
    public int LimitOfLiability { get; set; }
    public int PropertyContentPremium { get; set; }
    }
}

控制器:

public class TaxServiceController : Controller
{
    public ActionResult Index()
    {
        return View(new TaxService
        {
            Locations = new List<Location>{
                new Location()
            }
        });
    }

    //[HttpPost]
    //public ActionResult Location_Create(Location loc)
    //{
        //var x = new Location();
        //if (loc != null && ModelState.IsValid)
        //{
                //x.State = loc.State;
                //x.LocationNum = loc.LocationNum;
                //x.PropertyContentPremium = loc.PropertyContentPremium;
                //x.LimitOfLiability = loc.LimitOfLiability;
                //x.LiabilityPremium = loc.LiabilityPremium;
                //x.InlandMarinePremium = loc.InlandMarinePremium;
                //x.CargoPremium = loc.CargoPremium;
                //x.BasePremium = loc.BasePremium;
            //};
        //return (null);
    //}

    [HttpPost]
    public ActionResult Save(TaxService tax)
    {
        using (var svc = new StateTaxService.StateTaxServiceClient())
        {
            var locations = new List<StateTaxService.TaxLocationsRequest>();
            foreach (var location in tax.Locations)
            {
                locations.Add(new StateTaxService.TaxLocationsRequest
                {

与控制器中的 Location_Create 相同,我将其注释掉,因为它不起作用。

我在问题区域之后立即停止了控制器,foreach 语句,其中locations为空,错误“对象引用未设置为对象的实例”。在可变税中,Locations列表也是空的,让我相信该列表中实际上没有任何值。

编辑/解决方案:

我最终通过ClientTemplate在所有列之后添加格式来修复它,并将这个函数放在我视图的最后:

<script>

function index(dataItem) {
    var data = $("#Locations").data("kendoGrid").dataSource.data();
    return data.indexOf(dataItem);
}

</script>
4

1 回答 1

0

尝试:

@(Html.Kendo()
      .Grid<Johnson.Billing.Models.Location>()
      .BindTo(Model.Locations)

代替:

@(Html.Kendo().Grid(Model.Locations) 
于 2013-07-19T12:29:37.040 回答