I have a search function, but I would like LocationID to be an array of integers rather than just a single integer. I'm not sure how to do this since I want it to also be nullable. I've looked at doing int?[] but then I'd have to check the HasValue of every single entry. Is there a better way?
This is what I currently have:
public ActionResult Search(string? SearchString, int? LocationId,
DateTime? StartDate, DateTime? EndDate)
解决方案
Arrays are always reference types, as is string - so they're already nullable. You only need to use (and only can use) Nullable where T is a non-nullable value type.
So you probably want:
public ActionResult Search(string searchString, int[] locationIds,
DateTime? startDate, DateTime? endDate)
Note that I've changed your parameter names to follow .NET naming conventions, and changed LocationId to locationIds to indicate that it's for multiple locations.
You might also want to consider changing the parameter type to IList or even IEnumerable to be more general, e.g.
public ActionResult Search(string searchString, IList locationIds,
DateTime? startDate, DateTime? endDate)
That way a caller could pass in a List for example.