Undefined in Results yet TextField and ValueField are correct.

4 posts, 0 answers
  1. Michael
    Michael avatar
    36 posts
    Member since:
    Sep 2014

    Posted 26 Jul 2018 Link to this post

    Hi, I'm struggling with something that should be easy, so I hope you can point to something stupid I'm doing wrong.

    I have this MultiSelectFor.  When I go the GetCertifications method, I am returning the expected number of results, yet the display shows undefined for each one.  I'd expect that to happen if the fields were misnamed, but as far as I can tell I'm getting them correctly with the appropriate names.

     

    @(Html.Kendo().MultiSelectFor(m => m.CertificationList)
                          .DataTextField("CertTitle")
                          .DataValueField("Id")
                          .Placeholder("Select Certifications...")
                          .AutoBind(false)
                          .MinLength(3)
                          .Filter(FilterType.Contains)
                          .DataSource(source =>
                          {
                              source.Read(read =>
                              {
                                  read.Action("GetCertifications", "DemandForecastInfoSummary");
     
                              })
     
                          .ServerFiltering(true);
                          })
                      )

     

    public ActionResult GetCertifications(string text)
          {
              if (string.IsNullOrEmpty(text))
              {
                  return Json("", JsonRequestBehavior.AllowGet);
              }
              var rtnValue = new SelectList( DemandPlanService.GetAllCertifications(text).ToList(),"Id","CertTitle");
                
              return Json(rtnValue, JsonRequestBehavior.AllowGet);
          }

     

  2. Nencho
    Admin
    Nencho avatar
    1822 posts

    Posted 30 Jul 2018 Link to this post

    Hello Michael,

    The implementation in the demonstrated code seems correct and it looks like that the only possibility is if the fields are mistyped. You can doublecheck the names in the Network tab of your browser console, by exploring the JSON result from your controller. Please refer to this screenshot, where this is demonstrated.

    Regards,
    Nencho
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Michael
    Michael avatar
    36 posts
    Member since:
    Sep 2014

    Posted 30 Jul 2018 in reply to Nencho Link to this post

    Thanks Nencho, I was able to solve this myself, by simply not using a SelectList.  Instead I just return a Generic List of my objects but only populated each new object with the values I really needed (Id and CertTitle).  I'm not sure I understand WHY this fixed the issue, but I honestly spent way more time on the issue than I budgeted for, so I had to just be happy it worked and moved on.

     

    Mike

  4. Nencho
    Admin
    Nencho avatar
    1822 posts

    Posted 01 Aug 2018 Link to this post

    Hello Michael,

    I am happy to see that the experienced issue is now fixed. As for the issue itself - it is probably related with an uppercase for the first character of the fields. That was the reason why I suggested to inspect the request and the data in order to doublecheck the name of the fields.

    Regards,
    Nencho
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top