Can't send datetime parameter while update listview

3 posts, 0 answers
  1. Troy
    Troy avatar
    3 posts
    Member since:
    Sep 2012

    Posted 24 Oct 2012 Link to this post

    Hi all,
    I have problem while update listview. 2 parameter: CreateDate and LastUpdate are miss when send by POST or GET.

    Please let me know where is problem. Thank so much!

    Model:
    public partial class spGetCardPolicyByDiscountIDAndResID_Result
        {
            public short ConditionID { get; set; }
            public string ConditionName { get; set; }
            public string Note { get; set; }
            public System.DateTime CreateDate { get; set; }
            public long CreateBy { get; set; }
            public System.DateTime LastUpdate { get; set; }
            public long UpdateBy { get; set; }
            public long RestaurantID { get; set; }
            public int DiscountPolicyID { get; set; }
            public byte CardLevelIID { get; set; }
            public string CardLevelName { get; set; }
            public string Description { get; set; }
        }
    Controller:
    public ActionResult Update([DataSourceRequest] DataSourceRequest request, spGetCardPolicyByDiscountIDAndResID_Result card, string discountID, string restaurantID)
            {
                AccountSession accsession = (AccountSession)Session["UserTGNH"];
                bool success = ResCardDataAccess.GetInstance().Update(card, discountID, restaurantID, accsession.AccountID);
                if (success)
                {
                    return Json(ModelState.ToDataSourceResult(), JsonRequestBehavior.AllowGet);
                }
                else return null;
    }
    View:
    ---Template
    @model IEnumerable<TGNH.Models.spGetCardPolicyByDiscountIDAndResID_Result>
    @{
        string[] parameter = ViewBag.Parameter;
    }
    <div class="k-toolbar k-grid-toolbar">
        <a class="k-button k-button-icontext k-add-button" href="#"><span class="k-icon k-add"></span>Add new record</a>
    </div>


    <script id="card-list-view-template" type="text/x-kendo-template">
        <div class="product-view">
                <dl>
                    <dt>Card Name</dt>
                    <dd>${CardLevelName}</dd>
                    <dt>Description</dt>
                    <dd>${Description}</dd>
                    <dt>Condition</dt>
                    <dd>${ConditionName}</dd>
                    <dt>Note</dt>
                    <dd>${Note}</dd>
                </dl>
                <div class="edit-buttons">
                    <a class="k-button k-button-icontext k-edit-button" href="\\#"><span class="k-icon k-edit"></span>Edit</a>
                    <a class="k-button k-button-icontext k-delete-button" href="\\#"><span class="k-icon k-delete"></span>Delete</a>
                </div>
            </div>
    </script>


                        @(Html.Kendo().ListView<TGNH.Models.spGetCardPolicyByDiscountIDAndResID_Result>(Model)
                            .Name("cardlistView" + @parameter[0])
                            .TagName("div")
                            .ClientTemplateId("card-list-view-template")
                            .DataSource(dataSource => dataSource
                                .Model(model => model.Id("CardLevelIID"))
                                .PageSize(6)
                                .Create(create => create.Action("Create", "ResCard", new { discountID = @parameter[0], restaurantID = @parameter[1] }))
                                .Read(read => read.Action("GetCardPolicyByDiscountIDAndResID", "ResDiscountPolicy", new { discountID = @parameter[0], restaurantID = @parameter[1] }))
                                        .Update(update => update.Action("Update", "ResCard", new { discountID = @parameter[0], restaurantID = @parameter[1] }).Type(HttpVerbs.Post))
                                .Destroy(destroy => destroy.Action("Editing_Destroy", "ListView"))
                            )
                            .Editable()
                        )


    <script>
        $(function () {
            var listView = $("#cardlistView").data("kendoListView");


            $(".k-add-button").click(function (e) {
                listView.add();
                e.preventDefault();
            });
        });
    </script>
    ---EditorTemplate
    @model TGNH.Models.spGetCardPolicyByDiscountIDAndResID_Result
    <div class="product-view">
        <dl>
            <dt>Card Name</dt>
            <dd>
                @(Html.EditorFor(p=>p.CardLevelName))
                <span data-for="ProductName" class="k-invalid-msg"></span>
            </dd>
            <dt>Description</dt>
            <dd>
                @(Html.EditorFor(p=>p.Description))
                <span data-for="UnitPrice" class="k-invalid-msg"></span>
            </dd>
            <dt>Condition</dt>
            <dd>
                @(Html.EditorFor(p=>p.ConditionName))
                <span data-for="UnitsInStock" class="k-invalid-msg"></span>
            </dd>
            <dt>Note</dt>
            <dd>@(Html.EditorFor(p=>p.Note))</dd>
        </dl>
        <div class="edit-buttons">
            <a class="k-button k-button-icontext k-update-button" href="\\#"><span class="k-icon k-update"></span>Save</a>
            <a class="k-button k-button-icontext k-cancel-button" href="\\#"><span class="k-icon k-cancel"></span>Cancel</a>
        </div>
    </div>
  2. Frank
    Frank avatar
    4 posts
    Member since:
    Jun 2012

    Posted 24 Oct 2012 Link to this post

    I might be wrong (I use a completely different approach with my input forms), but I did not see the CreateBy / CreateDate values in the view. As far as I know, submitting the content would only submit values that are available in "qualified input fields", such as TextBox, TextArea, CheckBox and so on. Again, I might be wrong, since I most of the time use ASP.NET MVC Ajax Forms. You could try to add Hidden fields for the values that are missing:

    <div class="product-view">
        @Html.HiddenFor( m => m.CreateDate )
        @Html.HiddenFor( m => m.CreateBy )

        [ ... rest of the content ... ]

    </div>

    and try again. Oh, and "POST" would be the right thing to do imho.


    Regards,

    Frank


  3. Kendo UI is VS 2017 Ready
  4. Troy
    Troy avatar
    3 posts
    Member since:
    Sep 2012

    Posted 26 Oct 2012 Link to this post

    Thank you for your help, Frank!
    I added Hidden field for them, and I try to add more field with another type. But, all of field with datetime type can not send.
    Regard,
    Troy
Back to Top