title: How to Dynamically call a model property with a variable in asp.net MVC C# in razor
body: <p>Current Scenario:</p>
  
  <ul>
  <li><p>I have a model class wich has Descriptions in diferent languages, like Description_en , Description_sp , Description_fr .</p></li>
  <li><p>When a user selects his current language, I have a cookie 'culture' with that value.</p></li>
  </ul>
  
  <p>***** The objective is to call a different Description, when a different language is selected. If user selects fr, Description_fr should be called, and so on...</p>
  
  <p>My code:</p>
  
  <p>In ModelClass I have a reflection (has seen here: <a href="https://stackoverflow.com/questions/676608/how-to-call-a-property-of-an-object-with-a-variable-in-c-sharp-e-g-customer-fi">How to call a property of an object with a variable in C# e.g. customer.&amp;fieldName</a> ):</p>
  
  <pre><code>public class Something
      {
          public string Description_en { get; set; } 
          public string Description_sp { get; set; } 
          public string Description_fr { get; set; } 
  
          //Reflection, makes it possible to select a property to call with a variable
              public string GetPropertyValue(string fieldName)
              {
                  PropertyInfo prop = typeof(Something).GetProperty(fieldName);
                  return prop.GetValue(this, null).ToString();
              }
      }
  </code></pre>
  
  <p>In a razor Template I have:</p>
  
  <pre><code>@model IEnumerable&lt;baseTemplate.Models.Something&gt;
  
  &lt;table class="table"&gt;
      &lt;tr&gt;
          &lt;th data-lang=@culture&gt;
          &lt;!-- @culture is defined in current scope --&gt;
              @Html.DisplayNameFor(model =&gt; model.GetPropertyValue("Description_" + @culture)) 
          &lt;/th&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>When it runs to the property GetPropertyValue("...") the following error is displayed:</p>
  
  <blockquote>
    <p>Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.</p>
  </blockquote>
  
  <p>My question is: Is there is a way to do this?</p>
  
  <p>P.S. The obvious (and correct) possibility of...</p>
  
  <pre><code>if(@culture == "en"){@Html.DisplayNameFor(model =&gt; model.Description_en") }
  </code></pre>
  
  <p>... Shouldn't be an answer because it would create a 'Hell' of code to maintain afterwards :)</p>
  
  <p>Thank you for the possible help</p>