Blabla Blabla - 3 months ago 21
ASP.NET (C#) Question

Detect Empty result in JS

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;
}
})
}

Answer

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

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