Click here to Skip to main content
15,065,758 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
- called by selectbox go into function 'getDepAndMan()',

- there is a value taken from the selectbox (works)

- calls functions in the controller 'GetDepartmentAndManager' (works)

- controller returns value (works)

> {Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable<<>f__AnonymousType6<'string, string>>}

> Result View: [0] { UserDepartament = "there is value here / string", UserManager = "there is value here / string" }


- should go back to ajax and call 'succes: function (employee data)' (works)

- should assign values ​​to the fields (doesn't work)

- show an alert (work)

- show alert with values (doesn't work, show an alert with: undefined undefined)


View:
@(Html
     .DevExtreme()
     .SelectBox()
     .DataSource(d => d
          .Mvc()
      )
     .OnValueChanged("getDepAndMan")
  )
 @(Html.DevExtreme().TextBox()
      .ID("Id_department")
      .ReadOnly(true)
  )
 @(Html.DevExtreme().TextBox()
      .ID("Id_manager")
      .ReadOnly(true)
  )

<script type="text/javascript">

    function getDepAndMan() {

        
        var userId = {
           nazwaValueId: $("#idName").dxSelectBox("instance").option("value")
        };

        $.ajax({

            url: "@Url.Action("GetDepartmentAndManager", "Uzytkownicy")",
            type: "POST",
            dataType: "json",
            data: {"userId": JSON.stringify(userId)},
            cache: false,
            success: function (danePracownika) {
                  $("#Id_department")
                     .dxTextBox("instance")
                     .option("value", danePracownika.UserDepartament);
                 $("#Id_manager")
                     .dxTextBox("instance")
                    .option("value", danePracownika.UserManager);

                alert(danePracownika.UserDepartament + " " + danePracownika.UserManager);
            },
            failure: function (error) {
                alert(error);

            },
            error: function (error) {
                alert(error);
            }
        });
    }
</script>


Controller:
[HttpPost]
public ActionResult GetDepartmentAndManager(string userId) 
{
dynamic serializer = JsonConvert.DeserializeObject<IDictionary>(userId);

            var IdCzlowieka = serializer["nazwaValueId"];

            int IntIdCzlowieka = Convert.ToInt32(IdCzlowieka);
            var danePracownika = _uzytkownicyContext.Uzytkownicy.Where(x => x.Id == IntIdCzlowieka).Select(s => new
            {
                UserDepartament = s.Departament,
                UserManager = s.ManagerLogin

            });


   return Json(danePracownika);
}


return : //
> [0] { UserDepartament = "there is value here / string", UserManager = "there is value here / string" }

What I have tried:

The question is, what's wrong with the code, why it doesn't work for me?
Posted
Updated 8-Feb-20 4:19am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900