I want to display some concatenated fields in a webgrid column and receive this error when the concatenated fields have null values
SQL query:
SELECT *, T.Name AS Title, PT.Name AS PropertyType
FROM Properties AS P
LEFT OUTER JOIN Owners_Properties AS OP ON OP.PropertyId = P.PropertyId
LEFT OUTER JOIN Owners AS O ON O.OwnerId = OP.OwnerId
LEFT OUTER JOIN PropertyTypes AS PT ON PT.PropertyTypeId = P.PropertyTypeId
LEFT OUTER JOIN Titles AS T ON T.TitleId = O.TitleId
WHERE P.CondoId=@0 AND P.PropertyId=@1
HTML markup:
propertyGrid.Column("Propriétaire", format: (item) => item.Title+ ' ' + item.FirstName+ ' ' + item.LastName)
This problem occurs when ´two consecutives fields´ are NULL
I tried to modify my HTML code in the following way:
propertyGrid.Column("Owner", format: (item) => @Html.Raw((item.Title=!null) ? (item.Title+ ' ') : "")+ (item.FirstName=!null) ? (item.FirstName+ ' ') : "")+ ((item.LastName=!null) ? item.LastName : "")))
It should also be possible to avoid returning these NULL values but on the SQL query side but I didn't succeed neither. Life's hard ;-)