C# 有条件<;br>;C语言中的地址格式#

C# 有条件<;br>;C语言中的地址格式#,c#,asp.net,line,tostring,break,C#,Asp.net,Line,Tostring,Break,我正在格式化我的应用程序,以显示与特定工作通知单相关的地址。有时,地址会使用第二行。我不想使用以下内容: <%: ticket.ADDRESS2 %><br /> 这样,我在“get”(并非所有代码路径都返回值)处得到错误。我觉得我在做一件简单的事情。我只想让我的页面显示出来 地址行1 地址行2 城市、州邮政编码 或 地址行1 城市、州邮政编码 有人有什么建议吗?我查找了“条件中断”,但没有得到多少有用的回报。使用if语句 <%if (!string.IsNull

我正在格式化我的应用程序,以显示与特定工作通知单相关的地址。有时,地址会使用第二行。我不想使用以下内容:

<%: ticket.ADDRESS2 %><br />
这样,我在“get”(并非所有代码路径都返回值)处得到错误。我觉得我在做一件简单的事情。我只想让我的页面显示出来

地址行1
地址行2
城市、州邮政编码

地址行1
城市、州邮政编码

有人有什么建议吗?我查找了“条件中断”,但没有得到多少有用的回报。

使用if语句

<%if (!string.IsNullOrEmpty(ticket.ADDRESS2)) { %>

   <%: ticket.ADDRESS2 %><br />

<%} %>


使用if语句

<%if (!string.IsNullOrEmpty(ticket.ADDRESS2)) { %>

   <%: ticket.ADDRESS2 %><br />

<%} %>



我过去在MVC项目中所做的工作是,但很容易在WebForms的代码隐藏中完成的工作是:

var lines = new [] {
  contact.Name,
  contact.AddressLine1,
  contact.AddressLine2,
  contact.AddressLine3,
  contact.PostCode
};

var address = String.Join("<br/>", lines.Where(l => !String.IsNullOrWhitespace(l));
var行=新[]{
联系人姓名:,
联系地址1,
联系人:www.AddressLine2,
联系人:http://www.AddressLine3,
联系方式:邮政编码
};
var address=String.Join(“
”,lines.Where(l=>!String.IsNullOrWhitespace(l));

然后使用适当的方法将
地址
作为原始字符串写出。

我过去在MVC项目中做过的工作,但很容易在WebForms的代码隐藏中完成,就是:

var lines = new [] {
  contact.Name,
  contact.AddressLine1,
  contact.AddressLine2,
  contact.AddressLine3,
  contact.PostCode
};

var address = String.Join("<br/>", lines.Where(l => !String.IsNullOrWhitespace(l));
var行=新[]{
联系人姓名:,
联系地址1,
联系人:www.AddressLine2,
联系人:http://www.AddressLine3,
联系方式:邮政编码
};
var address=String.Join(“
”,lines.Where(l=>!String.IsNullOrWhitespace(l));

然后使用适当的方法将
地址作为原始字符串写出。

删除空行,然后使用添加换行符

// Get the address lines to be displayed
string[] lines = new string[]
{
   ticket.Address1,
   ticket.Address2,
   ticket.Address3,
   ticket.Address4,
   ticket.ZipCode,
};

// Remove blank lines
IEnumerable<string> filledLines = lines.Where(s => !string.IsNullOrWhitespace(s));

// Add newlines between each line
string html = string.Join(@"<br />", filledLines);
//获取要显示的地址行
字符串[]行=新字符串[]
{
票务地址1,
票务地址,
票务地址,
票务地址,
ticket.ZipCode,
};
//删除空行
IEnumerable filledLines=lines.Where(s=>!string.IsNullOrWhitespace(s));
//在每行之间添加换行符
string html=string.Join(@“
”,filledLines);
删除空行,然后使用添加换行符

// Get the address lines to be displayed
string[] lines = new string[]
{
   ticket.Address1,
   ticket.Address2,
   ticket.Address3,
   ticket.Address4,
   ticket.ZipCode,
};

// Remove blank lines
IEnumerable<string> filledLines = lines.Where(s => !string.IsNullOrWhitespace(s));

// Add newlines between each line
string html = string.Join(@"<br />", filledLines);
//获取要显示的地址行
字符串[]行=新字符串[]
{
票务地址1,
票务地址,
票务地址,
票务地址,
ticket.ZipCode,
};
//删除空行
IEnumerable filledLines=lines.Where(s=>!string.IsNullOrWhitespace(s));
//在每行之间添加换行符
string html=string.Join(@“
”,filledLines);
Perfect。这正是我想要的。太简单了,我把它复杂化了。谢谢!!(我还了解了HTML方面的工作原理!!太好了,很高兴我能帮上忙。如果这个答案解决了你的问题,一定要接受。Perfect。这正是我想要的。太简单了,我把它复杂化了。谢谢!!(我还了解了HTML端的工作原理!!非常好,很高兴我能提供帮助。如果这个答案解决了您的问题,请务必接受。感谢您的回复。如果我的格式需要变得更复杂,我将保留此书签作为参考。不过,我在代码中使用了另一个答案,因为它在我的简单si中工作得非常完美。)tuation!感谢您的回复。如果我的格式需要变得更复杂,我将保留此书签作为参考。不过我在代码中使用了另一个答案,因为它在我的简单情况下工作得非常完美!