Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8335817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:47:18+00:00 2026-06-09T03:47:18+00:00

I have a model called Lines. On it I have a address class that

  • 0

I have a model called Lines. On it I have a address class that contains a number of strings, i.e.:

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; }

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.

Currently in my cshtml page I am displaying the address as below:

@Html.DisplayFor(model => model.Address.ReferenceKey),
@Html.DisplayFor(model => model.Address.PremisesName),
@Html.DisplayFor(model => model.Address.PostTown),
@Html.DisplayFor(model => model.Address.Postcode),
@Html.DisplayFor(model => model.Address.County),
@Html.DisplayFor(model => model.Address.Country)

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.

public string ConcatAddress { get; set; }

Now were I am kind of stuck – in my controller I was doing the below to build up the string:

model.ConcatAddress = model.Address.ReferenceKey + model.Address.PremisesName....etc, etc

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:47:20+00:00Added an answer on June 9, 2026 at 3:47 am

    Add the strings that you want in a list, e.g.:

    var str = New List<string>();
    if (!string.IsNullOrEmpty(model.Address.ReferenceKey)) {
      str.Add(model.Address.ReferenceKey);
    }
    

    Then join the strings:

    return string.Join(",", str);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model called company that has_many users then users belongs_to company. class
I have a model called Person. I want User to inherit from Person. class
I have a model called Contact which has_one guest like so. class Contact <
I have a model called Customer in google app engine with python: class Customer(db.Model):
I have a model called Story that has two integer fields called views and
I have a model called MSG and it has a content:string in it. In
Let's say I have a class structure that is defined below: Class Item(models.Model): ...
I have a model called websites that has_many :likes , and of course another
I have a model class called Dashboard and it has an attribute 'team_members.' Like
I have a few things in various different files that get called from different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.