A couple of possibilities here
1. The
Model being passed in is
NULL
2. One of the properties of the Model.Item is
NULL
For the first case scenario, what I do is specifically check
before I try to iterate through it
@if (Model != null) {
foreach (var item in Model.Where(item => item != null)) {
For the second scenario, you can use
NULL Coalescing and Conditionals when calling the particular property
Member access operators - C# reference | Microsoft Docs[
^]
Expressions - C# language specification | Microsoft Docs[
^]
The way I handle this is via a static class for Extension Methods, which has routines for all of the data types that I use
using System {
public static partial class PublicExtensions {
public static string ForcedString(this object NullableObject, string DefaultValue = "") {
return (NullableObject == null ? DefaultValue : NullableObject.ToString().Trim());
}
And for your scenario it would be plumbed in like this
<span>@Html.DisplayFor(modelItem => item.Nome_Produto.ForcedString())</span>