Dynamically Set Model Properties in ASP.NET MVC
<p>I have a long list of check boxes that I need to display on a form. I get the list of check boxes from a table in the database and render them on the page. When the page is saved, I am saving the field name and value (as they are stored in the database) of each selected item.</p>

<p>I also have a model class that all of these check box fields map to, but I was thinking, since I have the field name and value, I would be able to set only the properties for which I have a field/value.</p>

<p>I was thinking I could just do something like this, but I know the syntax isn't correct:</p>

<pre><code>private void CreatePPAIndication(ReferralFormViewModel viewModel, Guid personId, Guid encId)
        {
            var ppaIndication = new PPAIndication();

            ppaIndication.enterprise_id = "00001";
            ppaIndication.practice_id = "0001";
            ppaIndication.person_id = personId;
            ppaIndication.enc_id = encId;
            // set more properties...

            // Here is where I would set a property for each selected check box.
            foreach (var indication in viewModel.Indications.Where(o =&gt; o.IsSelected))
            {
                var result = "ppaIndication." + indication.FieldName + "(" + indication.FieldValue + ")";
            }

            // How can I essentially "execute" the string in the line above?

            _context.PPAIndications.Add(ppaIndication);
        }
</code></pre>

<p>So, basically, I am wondering how I can essentially "execute" the "result" string as real code. Thank you in advance for any advice!</p>