title: how to extract keys and values from a list of object in asp.net core c#
body: <p>I passed an array of object key-value pairs from the frontend to the controller. refer here for clarification <a href="https://stackoverflow.com/questions/67870420/how-to-pass-array-of-objects-to-asp-net-core-controller-via-ajax/67871285#67871285">Pass array of objects to asp.net core controller via ajax</a></p>
  <p>The list is going to different tables, I want to loop the list and check those that start with &quot;product&quot; and save to the Product table, then those start with &quot;fee&quot; to Fee table etc.</p>
  <p>I am thinking of putting it in a dictionary to get the keys and the values, with that I can assign each value to Project object and Fee object.</p>
  <p><a href="https://i.stack.imgur.com/llTVm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/llTVm.png" alt="enter image description here" /></a></p>
  <pre><code>        public ActionResult CreateSetUp(List&lt;MerchantInfoSetUpViewModel&gt; collection)
          {
              try
              {
                  for (int i = 0; i &lt; collection.Count; i++)
                  {
                      var eachName = collection[i].Name; 
                      if (eachName.Substring(0, 7) == &quot;product&quot;)
                      {                        
                          //List&lt;string&gt; allValues = (from productFeeValue in collection select productFeeValue.Value).Distinct().ToList();                        //List&lt;string&gt; keyList = new List&lt;string&gt;(this.co)
                          ConfigureMerchantFee configureMerchantFee = new ConfigureMerchantFee
                          {        
                              //MerchantId = allValues.                       
                          };
                          productRepository.AddOneEntity(collection[i].Value);
                      }
                      if (eachName.Substring(0, 8) == &quot;product-&quot;)
                      {
                      } 
                      else { }              
                  }                
                  
                  return RedirectToAction(nameof(Index));            
              }catch{                
                  return null;            
              }        
          }
           
  </code></pre>