Check if element exists in mvc formcollection

I get some data in mvc controller as FormCollection. I would like to check if any particular key exists in the formcollection.

 public JsonResult FullRetailerUpdate(FormCollection data)
 {
     //I want to check if 
     //data["AnElement"] is exist
 }

Please, help.

+4
source share
1 answer

Try using .Contains(): -

 public JsonResult FullRetailerUpdate(FormCollection data)
 {
    if (data.AllKeys.Contains("AnElement")) 
    {
      // Your Stuff
    }
    else
    {
      // Your Stuff
    }   
 }
+11
source

All Articles