how to handle no data communication between ASP.net and angular JS? RRS feed

  • Question

  • User-1164047405 posted


    We have a web app which uses ASP.net web API in the backend and angular JS in the front end,looking for some suggestions on if the backend can send a JSON object with null values to angular JS(like in Option#1) and angular JS can parse it or in the cases where the keyvalues are null should the backend parse it and send as in #2?either ways is it a big deal?what are the pros and cons of each option?

    { "name":null, "age":null, "car":null }
    data:[] data:null

    Saturday, May 6, 2017 12:33 AM

All replies

  • User1068175894 posted
    It depends if you are requesting a list or an item

    If you are requesting a list you will never return null, worse case scenario return an empty array if there is no items

    If you are requesting an item and it is not found you should return null, if it is found then return the object with whatever properties it has

    On the angular side do:

    $scope.model.item = <data from svr> || {}

    Remember to mark as answer if this answer solves your issue
    Sunday, May 7, 2017 12:50 AM
  • User1068175894 posted


    Did my answer solved your issue?

    Please remember to click "Mark as Answer" the responses that resolved your issue.

    Tuesday, May 9, 2017 4:19 AM