Can anyone explain why this action returns ZERO results when “0” is passed to “page” parameter:
[HttpPost]
public ActionResult SearchProperties(string id, string offerTypeID, string propertyTypeID, string page)
{
int temp = 0;
var props = from s in db.Properties
where s.Approved && s.Available
select s;
if (!String.IsNullOrEmpty(id))
{
Int32.TryParse(id, out temp);
props = from s in props
where s.PropertyType.PropertyTypeCategoryID == temp
select s;
}
if (!String.IsNullOrEmpty(offerTypeID))
{
Int32.TryParse(offerTypeID, out temp);
props = from s in props
where s.OfferTypeID == temp
select s;
}
if (!String.IsNullOrEmpty(propertyTypeID))
{
Int32.TryParse(propertyTypeID, out temp);
props = from s in props
where s.PropertyTypeID == temp
select s;
}
props = props.OrderBy(s => s.PropertyID);
int i = 0, skip = 0;
if (!String.IsNullOrEmpty(page))
{
Int32.TryParse(page, out temp);
skip = temp * 10;
}
else
{
skip = 0;
}
props = props.Skip(skip).Take(10);
var marks = (from s in props.ToList()
select s);
return Json(new { markers = marks });
}
Is it because i am re-using the temp variable to tryparse?
Please enlighten me because this piece of code doesnt throw any exception or caution but just returns zero records…
Your code is more complex that it needs to be. Simplifying it should result in a correct result or, at least, make it easier to debug. Let the framework do the conversion to
intfor you. If the parameters aren’t required, make them nullable.