2

I have an ActionResult which return PartialView() or new EmptyResult(), How to detect in JS callback function if returned data is EmptyResullt()? I have tried many ways, i.e. compare with null or with undefined but no results. console.log(data) shows blank space. Any tips and tricks? :)

"more code":

Controller:

    public ActionResult Checkif(int d)
    {
        if (d == 2) return new EmptyResult();
        else return PartialView();
    }

Js function:

function sth ()
{
    $.get('/home/Checkif/', {d: 2}, function(data){
        if(data === null) //<---- this does not work
        {
            //then sth;
        }
    })
}
3
  • 1
    please share more code Commented Aug 8, 2016 at 17:20
  • 2
    You need to know the data type of data in order to check whether it is empty or not. Does it come back as an object? an array? a string? Try console.log(data) Commented Aug 8, 2016 at 17:27
  • 1
    So what is EmptyResult() returning, my guess it is not null. Commented Aug 8, 2016 at 17:28

1 Answer 1

2

Usually, checking for if (data) { // do something } will work.

To specifically check for empty string, using data === '' should work.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, if(data) works perfectly! Spent much time to find solution and I did not achieve positive results. Thanks you! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.