Brandon Lumsden
Brandon Lumsden

Reputation: 79

Compare IQueryable to String in MVC

I have this IQueryable here :

The way i would call the IQueryable would be like :

 var code = securityCodeCheck(item.SelectedDistrict);

and my comparison would be like:

if (item.DistrictCode == code)
{
     return view();
}

else{
     return RedirectToAction(....);
}

how would I go about being able to compare the 2 successfully?

Upvotes: 0

Views: 223

Answers (1)

scartag
scartag

Reputation: 17680

For the first problem you are selecting District.securityCode (which i assume is a string)

Try to select District as that would be the right IQueryable to fix the error since the method clearly defines it as a return type.

Code change would be as below.

var query = from District in db.Districts
 where District.leaID.Equals(district)
select District;

For problem 2.

You can use as below.

var code = securityCodeCheck(item.SelectedDistrict);

if(item.DistrictCode == code.First().securityCode)
{
//do stuff
}

Upvotes: 1

Related Questions