1

i wrote this controller:

[HttpPost]
    public JsonResult GetTrackList(POS_model item)
    {
        //item.item_code
        //item.track_type
        if (item.track_type != "Regular")
        {
            POS pos = new POS();
            DataTable dt = pos.GetTrackList(item.item_code, Convert.ToInt64(item.item_line_id), item.description, Convert.ToDouble(item.Qty), item.location, item.track_type);

            return Json(Utilities.GetTableRows(dt), JsonRequestBehavior.AllowGet);
        }
        else
        {
            return Json(new {
                    required = "false"
            }, JsonRequestBehavior.AllowGet);
        }
    }

and this script with ajax call:

$.ajax({
            type: 'POST',
            url: '@Url.Action("GetTrackList", "POS")',
            datatype: "json",
            data: JSON.stringify({ item_code: code, item_line_id: line_id, description: desc, Qty: qty, location: loc, track_type: t_type }),
            contentType: 'application/json; charset=utf-8',
            success: function (data) {
                var table = document.getElementById("tblTrackList");
                $.each(data, function (index, item) {
                    var row = table.insertRow(-1);

                    var checked = row.insertCell(0);
                    var uid = row.insertCell(1);
                    var id = row.insertCell(2);
                    var transaction_code = row.insertCell(3);
                    var transaction_type = row.insertCell(4);
                    var item_line_id = row.insertCell(5);
                    var item_code = row.insertCell(6);
                    var item_codename = row.insertCell(7);
                    var item_description = row.insertCell(8);
                    var lot_number = row.insertCell(9);
                    var expiry_date = row.insertCell(10);
                    var qty = row.insertCell(11);
                    var available_qty = row.insertCell(12);
                    var bin_code = row.insertCell(13);
                    var is_draft = row.insertCell(14);
                    var entity_id = row.insertCell(15);

                    $(checked).html(item["checked"].toString());
                    $(uid).html(item["uid"]);
                    $(id).html(item["id"]);
                    $(transaction_code).html(item["transaction_code"]);
                    $(transaction_type).html(item["transaction_type"]);
                    $(item_line_id).html(item["item_line_id"]);
                    $(item_code).html(item["item_code"]);
                    $(item_codename).html(item["item_codename"]);
                    $(item_description).html(item["item_description"]);
                    $(lot_number).html(item["lot_number"]);
                    $(expiry_date).html(item["expiry_date"]);
                    $(qty).html(item["qty"]);
                    $(available_qty).html(item["available_qty"]);
                    $(bin_code).html(item["bin_code"]);
                    $(is_draft).html(item["is_draft"]);
                    $(entity_id).html(item["entity_id"]);
                })
            },
            error: function (req, status, errorObj) {
                alert(errorObj.toString());
            }
        });

Screenshot Result: enter image description here

values of DataRable dt in Controller: enter image description here

in the images above, why are the expiry_date fields displayed incorrectly in the first image?

0

1 Answer 1

1

change $(expiry_date).html(item["expiry_date"]); to following code.

var date = new Date(parseInt(item["expiry_date"].substr(6)));
$(expiry_date).html(date);

if you want to format your date then you can also check This answer to format date

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.