title: System.NullReferenceException: 'Object reference not set to an instance of an object.' - In .NET Core 3.1
body: <p>I am making a BookEvent app using ASP.NET Core 3.1 MVC. I am facing this error <code>System.NullReferenceException: 'Object reference not set to an instance of an object.' Microsoft.AspNetCore.Mvc.Razor.RazorPage&lt;TModel&gt;.Model.get returned null.</code></p>
  <p>How can I fix it?</p>
  <p>I am trying to display all created events at the home page.</p>
  <h3>File <em>HomeController.cs</em></h3>
  <pre><code>[HttpGet]
  public IActionResult AllEvents()
  {
      var result = _eventAppService.GetAllEvent();
      var details = _mapper.Map&lt;EventViewModel&gt;(result.Data);
  
      if (result.IsSuccess)
      {
          this._logger.LogInformation(result.MainMessage.Text);
      }
      else
      {
          Message = $&quot;About page visited at {DateTime.UtcNow.ToLongTimeString()}&quot;;
          this._logger.LogError(Message);
          return View(&quot;Index&quot;);
      }
      return View(details);
  }
  </code></pre>
  <h3>File <em>EventAppServices.cs</em></h3>
  <pre><code>public OperationResult&lt;IEnumerable&lt;EventDTO&gt;&gt; GetAllEvent()
  {
      IEnumerable&lt;Event&gt; eventList = _eventRepository.Get(x =&gt; x.IsActive).ToList&lt;Event&gt;();
      List&lt;EventDTO&gt; eventDTOList = new List&lt;EventDTO&gt;();
      eventDTOList = _mapper.Map&lt;IEnumerable&lt;Event&gt;, List&lt;EventDTO&gt;&gt;(eventList);
      Message message = new Message(string.Empty, &quot;Return Successfully&quot;);
      var eventslist =  new OperationResult&lt;IEnumerable&lt;EventDTO&gt;&gt;(eventDTOList, true, message);
      return eventslist;
  }
  </code></pre>
  <h3>File <em>Index.cshtml</em></h3>
  <p><a href="https://i.stack.imgur.com/yIHE7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yIHE7.png" alt="Enter image description here" /></a></p>
  <h3>File EventViewModel.cs</h3>
  <pre><code>public class EventViewModel : ViewModel
  {
      [Display(Name = &quot;Title&quot;)]
      [Required]
  
      public string Title { get; set; }
  
      [Display(Name = &quot;Date&quot;)]
      [DataType(DataType.Date)]
      [Required]
      [DisplayFormat(DataFormatString = &quot;{0:yyyy-MM-dd}&quot;, ApplyFormatInEditMode = true)]
      public string Date { get; set; }
  
      [Display(Name = &quot;Location&quot;)]
      [Required]
      public string Location { get; set; }
  
      [Display(Name = &quot;Start Time&quot;)]
      [Required]
      [DataType(DataType.Time)]
      [DisplayFormat(DataFormatString = &quot;{0:HH:mm}&quot;, ApplyFormatInEditMode = true)]
      public string StartTime { get; set; }
  
      [Required]
      public string Type { get; set; }
      public EventType eventTypes;
  
      [Display(Name = &quot;Duration In Hours&quot;)]
      [Range(0, 4)] public virtual ICollection&lt;UserEvent&gt; UserEvent { get; set; }
      public int? Duration { get; set; }
  
      [MaxLength(50)]
      public string Description { get; set; }
  
      [MaxLength(500)]
      [Display(Name = &quot;Other Details&quot;)]
      public string OtherDetails { get; set; }
  
      [Display(Name = &quot;Invite Others&quot;)]
      public string InviteByEmail { get; set; }
  
      public int Count { get; set; }
  }
  </code></pre>