I have the following code :
Model code :
public class StudentViewModel
{
public string FirstAddress { get; set; }
public string SecondAddress { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zipcode { get; set; }
public string FullAddress
{
get
{
if (!string.IsNullOrEmpty(FirstAddress) && !string.IsNullOrEmpty(SecondAddress))
{
return $"{Address1}{Environment.NewLine}{Address2}{Environment.NewLine}{City}, {State} {Zipcode}";
}
else
{
return $"{Address1}{Environment.NewLine}{City}, {State} {Zipcode}";
}
}
set { this.FullAddress = value; }
}
}
This is how it's populated.
var record = context.StudentAdresses.Where(w => w.Active).Select(s => new {new StudentViewModel{FirstAddress =s.Address1, SecondAddress =s.Address2, City=s.City, State=s.State, Zipcode =s.Zipcode}).ToList();
View :
@model List<StudentViewModel>
@if (Model != null)
{
<div>
<table>
<thead>
<tr>
<th>Address</th>
</tr>
</thead>
<tbody>
@foreach (var record in Model)
{
<tr>
<td>
@record.FullAddress
</td>
</tr>
}
</tbody>
</table>
</div>
}
But the Full name does not appear with new line. Instead I get a single line of Address.
410 Address1 City, CA 32130
where as I need:
410 Address1
City, CA 32130
` tag. – Powerlord May 16 '20 at 14:55
in the view and can't do anything in my model? – TheFallenOne May 16 '20 at 15:30