Note that there are some explanatory texts on larger screens.

plurals
  1. POKendo grid values not being passed to model
    primarykey
    data
    text
    <p>The information a user puts into the grid seems to not actually pass into the model (my theory), returning a <code>null</code> value in the controller. I have tried various little fixes, and have looked around it for quite some time, but dont have the experience to see the issue here. Can anyone offer any help here?</p> <p><strong>View:</strong></p> <pre><code>@model Johnson.Billing.Models.TaxService @using(Html.BeginForm("Save", "TaxService")) { &lt;div&gt; @(Html.Kendo().Grid(Model.Locations) .Name("Locations") .Columns(columns =&gt; { columns.Command(command =&gt; { command.Destroy(); }).Width(80); columns.Bound(o =&gt; o.State).Title("State").EditorTemplateName("TaxService"); columns.Bound(o =&gt; o.LocationNum).Title("Loc #"); columns.Bound(o =&gt; o.BasePremium).Title("Base Prem:").Format("{0:c}"); columns.Bound(o =&gt; o.CargoPremium).Title("Cargo Prem:").Format("{0:c}"); columns.Bound(o =&gt; o.InlandMarinePremium).Title("Inland Marine Prem:").Format("{0:c}"); columns.Bound(o =&gt; o.LiabilityPremium).Title("Liability Prem:").Format("{0:c}"); columns.Bound(o =&gt; o.LimitOfLiability).Title("Limit of Liability:").Format("{0:c}"); columns.Bound(o =&gt; o.PropertyContentPremium).Title("Property Content Prem:").Format("{0:c}"); }) .ToolBar(toolbar =&gt; toolbar.Create().Text("Add a State Tax Calculation")) .Editable(editable =&gt; editable.Mode(GridEditMode.InCell)) .DataSource(dataSource =&gt; dataSource .Ajax() .ServerOperation(false) .Model(model =&gt; model.Id(o =&gt; o.LocationNum)) //.Create(update =&gt; update.Action("Location_Create", "TaxService")) )) &lt;/div&gt; &lt;input type="submit" value="Test Taxes" /&gt; } </code></pre> <p>(The create function was something I added in recently that didnt work, so I commented it out for now)</p> <p><strong>Model:</strong></p> <pre><code> 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&lt;Location&gt; 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; } } } </code></pre> <p><strong>Controller:</strong></p> <pre><code>public class TaxServiceController : Controller { public ActionResult Index() { return View(new TaxService { Locations = new List&lt;Location&gt;{ new Location() } }); } //[HttpPost] //public ActionResult Location_Create(Location loc) //{ //var x = new Location(); //if (loc != null &amp;&amp; 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&lt;StateTaxService.TaxLocationsRequest&gt;(); foreach (var location in tax.Locations) { locations.Add(new StateTaxService.TaxLocationsRequest { </code></pre> <p>Same thing with the Location_Create in the controller, I commented it out as it did not work. </p> <p>I stopped the controller right after the issue area, the foreach statement, where <code>locations</code> is null, with the error "Object reference not set to an instance of an object." In the variable tax, the <code>Locations</code> list is also null, bringing me to believe that there arent actually any values in that list.</p> <p><strong>EDIT/SOLUTION:</strong></p> <p>I ended up fixing it by adding a <code>ClientTemplate</code> format after all the columns, along with this function placed at the very end of my view:</p> <pre><code>&lt;script&gt; function index(dataItem) { var data = $("#Locations").data("kendoGrid").dataSource.data(); return data.indexOf(dataItem); } &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload