0

This is my linq query but here I am not getting null. In the result set in jquery code I am getting null

var Data = await (from Names in apiDbContext.name.AsNoTracking()
   .Where(a => a.IsActive == true) orderby NamesList.Name select NamesList)
   .ToListAsync(); 

Below is my screen shot where i am getting null in the data because of this null i am getting error

Uncaught TypeError: Cannot read property 'username' of null.

$.ajax({
      type: "GET",
      url: remote_url,
      async: false,
      success: function(data) { 
    /* Near this data i am getting last record as null because of this 
       I am getting error as Cannot read property 'username' of null  */
        $.each(data, function(key, val) {
          var title = val[Text];
        })
      })
mplungjan
  • 169,008
  • 28
  • 173
  • 236
sweety
  • 1
  • 1
    You can filtered values in backend code.for example with linq array.Where(q=> !string.IsNullOrEmpty(q)) – hakantopuz Dec 10 '20 at 11:58
  • var arr = ["",1,2,3,4,5,6,'123',33,'asd',"",'',1,'']; arr = arr.filter(function(value) { return value !== "" && value !== null; }); console.log(arr); ... for more details https://stackoverflow.com/questions/12745800/how-to-remove-null-values-from-an-array-using-jquery – Parth Raval Dec 10 '20 at 11:58
  • I had already tried this parth but still i am getting the same exception – sweety Dec 10 '20 at 12:01
  • To remove empty null or blank values from an array please check [this answer](https://stackoverflow.com/questions/281264/remove-empty-elements-from-an-array-in-javascript) – Nads Dec 10 '20 at 12:02
  • var Data = await (from Names in apiDbContext.name.AsNoTracking().Where(a => a.IsActive == true) orderby NamesList.Name select NamesList).ToListAsync(); this is my linq query but here i am not getting null in the result set in jquery code i am getting null – sweety Dec 10 '20 at 12:04

0 Answers0