title: Concatenate a string for DisplayFor
body: <p>I have a model called Lines.  On it I have a address class that contains a number of strings, i.e.:</p>
  
  <pre><code>public string ReferenceKey { get; set; }
  public string Country { get; set; }
  public string County { get; set; }
  public string Postcode { get; set; }
  public string PremisesName { get; set; }
  public string PremisesName { get; set; }
  </code></pre>
  
  <p>I get information back from a webservice call to an outside party and then populate these fields with the returned data - note in some cases they may not return everything so County or PostTown for example may be returned empty.</p>
  
  <p>Currently in my cshtml page I am displaying the address as below:</p>
  
  <pre><code>@Html.DisplayFor(model =&gt; model.Address.ReferenceKey),
  @Html.DisplayFor(model =&gt; model.Address.PremisesName),
  @Html.DisplayFor(model =&gt; model.Address.PostTown),
  @Html.DisplayFor(model =&gt; model.Address.Postcode),
  @Html.DisplayFor(model =&gt; model.Address.County),
  @Html.DisplayFor(model =&gt; model.Address.Country)
  </code></pre>
  
  <p>It works fine when all data is returned however if some fields are Blank it would show for e.g - REF1,,,POSTCODE,County,Country  - i.e the fields it doesnt have a value for wont be printed but the commas will which doesnt look very good.  My idea was to add another string to my model like below.</p>
  
  <pre><code>public string ConcatAddress { get; set; }
  </code></pre>
  
  <p>Now were I am kind of stuck - in my controller I was doing the below to build up the string:</p>
  
  <pre><code>model.ConcatAddress = model.Address.ReferenceKey + model.Address.PremisesName....etc, etc
  </code></pre>
  
  <p>What would I have to do to replace the double commas with one, etc depending on if the value. A string.IsNullorEmpty before each value check perhaps but what on the replace?</p>