This is a migrated thread and some comments may be shown as answers.

Can't send datetime parameter while update listview

2 Answers 101 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Troy
Top achievements
Rank 1
Troy asked on 24 Oct 2012, 09:24 AM
Hi all,
I have problem while update listview. 2 parameter: CreateDate and LastUpdate are miss when send by POST or GET.
CardLevelIID 1
CardLevelName Member
ConditionID 1
ConditionName Khi mua đặt từ 5 bàn trở lên
CreateBy 1
Description Only Member
DiscountPolicyID 1
Note Chú ý chỉ áp dụng cho những thành viên VIP
RestaurantID 4
UpdateBy 2

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 Answers, 1 is accepted

Sort by
0
Frank
Top achievements
Rank 1
answered on 24 Oct 2012, 12:25 PM
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


0
Troy
Top achievements
Rank 1
answered on 27 Oct 2012, 03:37 AM
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
Tags
ListView
Asked by
Troy
Top achievements
Rank 1
Answers by
Frank
Top achievements
Rank 1
Troy
Top achievements
Rank 1
Share this question
or