Check whether an element exists in mvc formcollection
I know that the question was about FormCollection
but for those using IFormCollection
here is the solution.
public IActionResult GetProjectDelivery(IFormCollection data)
{
if (data.ContainsKey("AnElement"))
{
// do stuff
}
else
{
// do stuff
}
}
Try using .Contains()
:-
public JsonResult FullRetailerUpdate(FormCollection data)
{
if (data.AllKeys.Contains("AnElement"))
{
// Your Stuff
}
else
{
// Your Stuff
}
}