1

ワーカー名と詳細を含む kendodropdown リストがあります...選択したワーカーの ID を取得して保存できるようにするにはどうすればよいですか...保存するたびに ID に null 値が返されます..助けてくれた人に感謝します

私のコードは次のとおりです。

<input id="titles" class:"validate[required] inputLong" style="width: 400px;"  />

 $(document).ready(function () {
        var clientCusPosId = $("#clientCusPosId").val();
        $("#titles").kendoDropDownList({
                        dataTextField: "workerName",
                        dataValueField: "workerID",
                        autoBind: false,

                        // define custom template
                        template:
                                      '<h5>${ data.workerName }</h5>' +
                                      '<p>${ data.workerID }</p>' +
                                      '<p>${ data.AvailableDay_LookID }</p>' +
                                      '<p>${ data.StartTime } - ${ data.EndTime }</p>',
                        optionLabel: "Assign worker",

                        dataSource: {
                            transport: {
                                read: {
                                    url: '/Client/LoadWorkerDropdownList?clientCusPosId=' + clientCusPosId,
                                    dataType: "json",
                                    type: "POST"
                                }
                            }
                        }

                    });

                    var dropdownlist = $("#titles").data("kendoDropDownList");
                    dropdownlist.list.width(250);
 });

私のコントローラー:

[Authorize]
[HttpPost]
public ActionResult ClientWorkerPositionSave(FormCollection formCollection)
{
    String msg = String.Empty;
    String clientWorkerPosId = formCollection["clientWorkerPosId"];
    String clientID = formCollection["clientId"];
    String clientCusId = formCollection["clientCusPosId"];
    String workerID = formCollection["titles"];




    Client_Worker_Position clientCusPos = new Client_Worker_Position();
    try
    {
        if (String.IsNullOrWhiteSpace(clientWorkerPosId) || clientWorkerPosId == "0")
        {
            clientCusPos.ClientCustomerPositionID = Convert.ToInt32(clientCusId);
            clientCusPos.WorkerID = Convert.ToInt32(workerID);
            clientCusPos.ClientID = Convert.ToInt32(clientID);

            clientCusPos.DateCreated = DateTime.UtcNow;
            clientCusPos.DateModified = DateTime.UtcNow;
            clientCusPos.CreatedBy = User.Identity.Name;
            clientCusPos.ModifiedBy = User.Identity.Name;

            db.Client_Worker_Position.Add(clientCusPos);
        }
        else
        {
            int id = Convert.ToInt32(clientWorkerPosId);
            clientCusPos = (from a in db.Client_Worker_Position
                            where a.ID == id
                            select a).SingleOrDefault();


            clientCusPos.ClientCustomerPositionID = Convert.ToInt32(clientCusId);
            clientCusPos.WorkerID = Convert.ToInt32(workerID);
            clientCusPos.ClientID = Convert.ToInt32(clientID);


            clientCusPos.DateModified = DateTime.UtcNow;
            clientCusPos.ModifiedBy = User.Identity.Name;
        }
    }
    catch (Exception)
    {
        msg = "Failed to save";
    }

    db.SaveChanges();

    if (String.IsNullOrWhiteSpace((msg)))
    { TempData["message"] = "Saved Successfully."; }
    else if (msg != "")
    { TempData["message"] = msg; }

    return RedirectToAction("ClientCustomerDetails", new { });
}
4

1 に答える 1