I am trying to concatenate for a label. If a field contains null
then entire concatenate result is null
.
[HttpGet]
public ActionResult PMAByPC(string PartnerCode)
{
var result = (from N in _POSContext.PMAs
where (N.PartnerCode == PartnerCode)
select new
{
label = N.Address1 + " | " + N.Address2 + " | " + N.City,
id = N.ID
});
return Json(result);
}
Here, if data is not present in of the fields, label becomes null
.
I tried with
select new { label = N.Address1 ?? "?" + " | " + N.Address2 ?? "?" + " | " + N.City ?? "?", id = N.ID }
then it takes only N.Address1
value and ignores the rest of the fields.
new { label = $"{N.Address1}|{N.Address2}|{N.City}", id = N.ID }
give the same results? learn.microsoft.com/en-us/dotnet/csharp/language-reference/…