2

Hello I am using Kendo grid to edit price lists.

I am trying to edit single value in table:

@(Html.Kendo().Grid(Model).Name("PriceList")
    .Columns(columns =>
    {
        columns.Bound(p => p.Id).Hidden();
        columns.Bound(p => p.Name);
        columns.Bound(p => p.ValidFrom).Format("{0:dd.MM.yyyy h:mm:ss}");
        columns.Bound(p => p.ValidTill).Format("{0:dd.MM.yyyy h:mm:ss}");
        columns.Bound(p => p.Created).Format("{0:dd.MM.yyyy h:mm:ss}");
        columns.Bound(p => p.UserName);
        columns.Bound(p => p.FilePath);
        columns.Command(command => { command.Edit(); command.Destroy(); });
    })
    .DataSource(dataSource => dataSource.Ajax()
            .Model(model =>
            {
                model.Id(p => p.Id);
                model.Field(p => p.ValidFrom).Editable(false);
                model.Field(p => p.ValidTill).Editable(true);
                model.Field(p => p.Created).Editable(false);
                model.Field(p => p.UserName).Editable(false);
                model.Field(p => p.FilePath).Editable(false);
                model.Field(p => p.Name).Editable(false);
        })
        .Read("PriceList_Read", "Admin")       
        .Destroy("PriceList_Editing_Destroy", "Admin")
        .Update(update=>update.Action("PriceList_Editing_Update", "Admin"))
        .Events(e=>e.Error("error_handler"))
    )   
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .AutoBind(true)
)

And I am having troubles passing edited value in grid to my controller:

public ActionResult PriceList_Editing_Update([DataSourceRequest] DataSourceRequest request, PriceListViewModel model)
        {

                    int Id = model.Id;
                    string Name = model.Name;
                    DateTime date = model.ValidTill; // 0001 00:00:00 value all the time

            return View("Index", GetViewResult());
        }

I am always getting back empty datetime value (by empty I mean {1. 1. 0001 0:00:00}) same problem is with 2 other columns using DateTime property (Created and ValidFrom). Rest of the values are posted back correctly. I was trying to get those values using string DateTillStr = Request.Params["ValidTill"]; but if I check my GET in firebug I can see grid is not sending back this value inside Request it sends only NON Datetime values of my model object. Like this:

Actual  false
FilePath    D:\Projects\CPSkla\CPSkla\App_Data\Cen°k 2012_10.xlsx
Id  23
Name    Testovací ceník
User    0
User1   null
UserName    djezek

Nothing more nothing less, only these 7 attributes I am missing rest 4 from my model:

public partial class PriceListView
{
    public int Id { get; set; }
    public int User { get; set; }
    public string Name { get; set; }
    public System.DateTime ValidFrom { get; set; }
    public System.DateTime ValidTill { get; set; }
    public string FilePath { get; set; }
    public Nullable<System.DateTime> Created { get; set; }
    public Nullable<System.DateTime> Updated { get; set; }
    public bool Actual { get; set; }
    public string UserName { get; set; }
}

Is there some other way to post these data back? I figured out I can attach additional data to Update request but I had an issue how to identify edited row in the table in javascript function (I know how to identify selected value but not edited).

I figured out using firebug that calendar picker inside kendo grid isnt actualy puting its selected value into input assigned to hold date value. Any thoughts?

tereško
  • 58,060
  • 25
  • 98
  • 150
user1753220
  • 21
  • 1
  • 2

2 Answers2

1

Using the save event of the grid - you can see the actual values gathered from the input fields, the model (dataItem) and event the HTML element which is used like a container for the input elements.

Also if you want to send additional values (or just send that problematic field in a different way use the data function of the update configuration).

Petur Subev
  • 19,983
  • 3
  • 52
  • 68
1

If my memory serves me right I think this is a Culture Issue with dates and times and is not specific to Kendo UI but to ASP.NET MVC.

So for example if the expected date format string is mm/dd/yyyy and the date is coming in as dd/mm/yyyy you will get null date value (0001 00:00:00)

See this SO Question

MVC DateTime binding with incorrect date format

hope this helps

Community
  • 1
  • 1
SimonGates
  • 5,961
  • 4
  • 40
  • 52