title: Why does my Content field return NULL since I initialized the variable and assigned to db field
body: <p>I have a problem which I have no idea where I made mistake since I am beginner in ASP.NET CORE MVC.
  I am creating a Ticketing System where the user can create a ticket and describe a problem. Once the ticket is sent
  <code>Admin</code> can send a message to <code>User</code>. Right now, this is where the problem starts.
  When I log in as <code>Admin</code> and try to answer the ticket, my message is always null or empty. I try to debug and see what happens and <code>Content</code> is always <code>null</code>.
  Here is my GET method:</p>
  <pre class="lang-cs prettyprint-override"><code>public IActionResult Upsert(int? Id)
  {
      DiscussionTicketVM discTicketVM = new DiscussionTicketVM()
      {
          ApplicationUser = new ApplicationUser(),
          Discussion = new Discussion(),
          Ticket = new Ticket()
      };
      
      if (Id == null)
      {
          return View(discTicketVM);
      }
      
      discTicketVM.Discussion = _unitOfWork.Discussion.Get(Id.GetValueOrDefault());
      
      if (discTicketVM.Discussion == null)
      {
          NotFound();
      }
      
      return View(discTicketVM);
  }
  </code></pre>
  <p>And here is my <code>POST</code> method where the magic starts</p>
  <pre class="lang-cs prettyprint-override"><code> public IActionResult Upsert(string message, int ticketId, DiscussionTicketVM discTikVM)
          {
              
              var users = _unitOfWork.ApplicationUser.GetAll(x =&gt; x.Id == x.UserName);
              var userName = User.FindFirstValue(ClaimTypes.Email);
              var user = HttpContext.User.Identity.Name;
             
  
              if (ModelState.IsValid)
              {
                  if (discTikVM.Discussion.Id == 0)
                  {
                     
                      _unitOfWork.Discussion.Add(discTikVM.Discussion);
                  }
                  else
                  {
                      _unitOfWork.Discussion.Update(discTikVM.Discussion);
                  }
                  _unitOfWork.Save();
                  return View(discTikVM);
              }
  
              return View(discTikVM);
          }
  </code></pre>
  <p>Regarding this I created DiscussionModel which is the following:</p>
  <pre class="lang-cs prettyprint-override"><code>public class Discussion
  {
      [Key]
      public int Id { get; set; }
      
      [Display(Name = &quot;Odgovor&quot;)]
      public string Content { get; set; }
      
      [Display(Name = &quot;Datum i vrijeme&quot;)]
      public DateTime DateAndTime { get; set; } = DateTime.Now;
      
      public string UserId { get; set; }
      
      [ForeignKey(&quot;UserId&quot;)]
      public ApplicationUser ApplicationUser { get; set; }
      
      public int? TicketId { get; set; }
      
      [ForeignKey(&quot;TicketId&quot;)]
      public Ticket Ticket { get; set; }
  }
  </code></pre>
  <p>And ViewModel:</p>
  <pre class="lang-cs prettyprint-override"><code>public class DiscussionTicketVM
  {
      public Discussion Discussion { get; set; }
      public Ticket Ticket { get; set; }
      public ApplicationUser ApplicationUser { get; set; }
  }
  </code></pre>
  <p>And also my View</p>
  <pre><code>    @model VmSTicketing.Models.ViewModels.DiscussionTicketVM
      @{
          ViewData[&quot;Title&quot;] = &quot;OpenDiscussion&quot;;
          Layout = &quot;~/Views/Shared/AdminLTE/_Layout.cshtml&quot;;
          
      }
      
      &lt;h2 class=&quot;text-info text-left&quot;&gt;Odgovori na tiketu&lt;/h2&gt;
      
      &lt;!--StyleSheet--&gt;
      &lt;link href=&quot;~/css/discussion.css&quot; rel=&quot;stylesheet&quot; /&gt;
      
      &lt;div class=&quot;container padding-bottom-3x mb-2&quot;&gt;
          &lt;div asp-validation-summary=&quot;ModelOnly&quot; class=&quot;text-danger&quot;&gt;&lt;/div&gt;
          &lt;input type=&quot;hidden&quot; asp-for=&quot;@Model.Discussion.Id&quot; /&gt;
          &lt;div class=&quot;row&quot;&gt;
              &lt;div class=&quot;col-lg-8&quot;&gt;
                  &lt;div class=&quot;padding-top-2x mt-2 hidden-lg-up&quot;&gt;&lt;/div&gt;
                  &lt;!-- Messages--&gt;
                  &lt;div class=&quot;comment&quot;&gt;
                      &lt;div class=&quot;comment-author-ava&quot;&gt;&lt;img src=&quot;https://bootdey.com/img/Content/avatar/avatar6.png&quot; alt=&quot;Avatar&quot;&gt;&lt;/div&gt;
                      &lt;div class=&quot;comment-body&quot;&gt;
                          &lt;p class=&quot;comment-text&quot;&gt;&lt;/p&gt;
                          &lt;div class=&quot;comment-footer&quot; asp-for=&quot;Discussion.Content&quot;&gt;&lt;span class=&quot;comment-meta&quot;&gt;&lt;/span&gt;&lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
      
                  &lt;!-- Reply Form--&gt;
                  &lt;h5 class=&quot;mb-30 padding-top-1x&quot;&gt;Leave Message&lt;/h5&gt;
                  &lt;form method=&quot;post&quot; asp-controller=&quot;Discussion&quot; asp-action=&quot;SendDisucssion&quot;&gt;
                      &lt;div class=&quot;form-group&quot;&gt;
                          &lt;textarea asp-for=&quot;Discussion.Content&quot; class=&quot;form-control form-control-rounded&quot;&gt;&lt;/textarea&gt;
                      &lt;/div&gt;
                      &lt;div class=&quot;text-right&quot;&gt;
                          &lt;button class=&quot;btn btn-outline-primary&quot; asp-controller=&quot;Discussion&quot; asp-action=&quot;Upsert&quot; type=&quot;submit&quot;&gt;Submit Message&lt;/button&gt;
                      &lt;/div&gt;
                      &lt;div class=&quot;text-left&quot;&gt;
                          &lt;button class=&quot;btn btn-primary&quot; asp-action=&quot;Index&quot; asp-controller=&quot;Ticket&quot;&gt;Nazad&lt;/button&gt;
                      &lt;/div&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  <p>A note before any discussion starts: I am trying to find a solution in google and I see that <code>SignalR</code> is one of the solutions to make real-time conversation, but in my case, I want first to create conversation and whatever before I update to SignalR, so I am not using <code>SignalR</code>.
  Is there anyone who can guide me and tell me what to do in this case? Where did I make a mistake?
  What should I focus on?</p>
  <p><strong>UPDATE</strong></p>
  <p>IUnitOfWorks.cs</p>
  <pre><code>public interface IRepository&lt;T&gt; where T : class
      {
          T Get(int Id);
  
          IEnumerable&lt;T&gt; GetAll(
              Expression&lt;Func&lt;T, bool&gt;&gt; filter = null,
              Func&lt;IQueryable&lt;T&gt;, IOrderedQueryable&lt;T&gt;&gt; orderBy = null,
              string includeProperties = null
              );
  
          IEnumerable&lt;T&gt; GetFirstOrDefault(
              Expression&lt;Func&lt;T, bool&gt;&gt; filter = null,
              string includeProperties = null
              );
  
          void Add(T entity);
          void Remove(int Id);
          void Remove(T entity);
          void RemoveRange(IEnumerable&lt;T&gt; entity);
      }
  
   public class Repository&lt;T&gt; : IRepository&lt;T&gt; where T : class
      {
          private readonly ApplicationDbContext _db;
          internal DbSet&lt;T&gt; dbSet;
  
          public Repository(ApplicationDbContext db)
          {
              _db = db;
              this.dbSet = _db.Set&lt;T&gt;();
          }  
  
  
          public void Add(T entity)
          {
              dbSet.Add(entity);
          }
  
          public T Get(int Id)
          {
              return dbSet.Find(Id);
          }
  
          public IEnumerable&lt;T&gt; GetAll(Expression&lt;Func&lt;T, bool&gt;&gt; filter = null, Func&lt;IQueryable&lt;T&gt;, IOrderedQueryable&lt;T&gt;&gt; orderBy = null, string includeProperties = null)
          {
              IQueryable&lt;T&gt; query = dbSet;
              if (filter != null)
              {
                  query = query.Where(filter);
  
              }
  
              if(includeProperties != null)
              {
                  foreach (var includeProp in includeProperties.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                  {
                      query = query.Include(includeProp);
                  }
              }
  
              if(orderBy != null)
              {
                  return orderBy(query).ToList();
              }
  
              return query.ToList();
          }
  
          public IEnumerable&lt;T&gt; GetFirstOrDefault(Expression&lt;Func&lt;T, bool&gt;&gt; filter = null, string includeProperties = null)
          {
              IQueryable&lt;T&gt; query = dbSet;
              if (filter != null)
              {
                  query = query.Where(filter);
  
              }
  
              if (includeProperties != null)
              {
                  foreach (var includeProp in includeProperties.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                  {
                      query = query.Include(includeProp);
                  }
              }
  
              yield return query.FirstOrDefault();
          }
  
          public void Remove(int Id)
          {
              T entity = dbSet.Find(Id);
              Remove(entity);
          }
  
          public void Remove(T entity)
          {
              dbSet.Remove(entity);
          }
  
          public void RemoveRange(IEnumerable&lt;T&gt; entity)
          {
              dbSet.RemoveRange(entity);
          }
      }
  </code></pre>