title: The parameters dictionary contains a null entry for parameter 'messageId' MVC
body: <p><a href="https://i.stack.imgur.com/xnkmP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xnkmP.png" alt="http://localhost:55245/Messages/ReplyMessage/39"></a></p>
  
  <p>This error appears when I'm training to post reply message and insert it in Replies Table using message id , I think the problem from the View when the id is calling </p>
  
  <pre><code>@using (Html.BeginForm("ReplyMessage", "Messages", FormMethod.Post, new 
  { id = "form-reply-message", messageId = @ViewBag.MessageId  }))
  </code></pre>
  
  <p>Any idea what I should change </p>
  
  <p>Controller Get Method:</p>
  
  <pre><code>   public ActionResult ReplyMessage(int? Id, int? page)
      {
  
          MessageReplyViewModel vm = new MessageReplyViewModel();
  
          if (Id != null)
          {
  
              var replies = dbContext.Replies.Where(x =&gt; x.MessageId == Id.Value).OrderByDescending(x =&gt; x.ReplyDateTime).ToList();
              if (replies != null)
              {
                  foreach (var rep in replies)
                  {
                      MessageReplyViewModel.MessageReply reply = new MessageReplyViewModel.MessageReply();
                      reply.MessageId = rep.MessageId;
                      reply.Id = rep.Id;
                      reply.ReplyMessage = rep.ReplyMessage;
                      reply.ReplyDateTime = rep.ReplyDateTime;
                      reply.MessageDetails = dbContext.Messages.Where(x =&gt; x.Id == rep.MessageId).Select(s =&gt; s.MessageToPost).FirstOrDefault();
                      reply.ReplyFrom = rep.ReplyFrom;
                      vm.Replies.Add(reply);
                  }
  
              }
              else
              {
                  vm.Replies.Add(null);
              }
  
  
              ViewBag.MessageId = Id.Value;
          }
  
          return View(vm);
  </code></pre>
  
  <p>Controller PostMethod :</p>
  
  <pre><code> [HttpPost]
      [Authorize]
      public ActionResult ReplyMessage(MessageReplyViewModel vm, int messageId)
      {
          if (vm.Reply.ReplyMessage != null)
          {
              Models.Reply _reply = new Models.Reply();
              _reply.ReplyDateTime = DateTime.Now;
              _reply.MessageId = messageId;
              _reply.ReplyMessage = vm.Reply.ReplyMessage;
              dbContext.Replies.Add(_reply);
              dbContext.SaveChanges();
  
          }
  
          return RedirectToAction("Index", "Message");
  </code></pre>
  
  <p>View :</p>
  
  
  
  <pre class="lang-html prettyprint-override"><code> @using (Html.BeginForm("ReplyMessage", "Messages", FormMethod.Post, new { id = "form-reply-message", messageId = @ViewBag.MessageId  }))
  {
   if (!ViewData.ModelState.IsValid)
   {
  
   @Html.ValidationSummary(true)
  
   }
   @Html.HiddenFor(model =&gt; model.Reply.MessageId);
   @Html.TextAreaFor(p =&gt; p.Reply.ReplyMessage, new { @rows = 2, @class = "form-control" })
  @Html.ValidationMessageFor(model =&gt; model.Reply.ReplyMessage)
  
  &lt;input type="submit" class="btn btn-primary btn-success" value="Reply" id="btn-reply-message"&gt;
  
   }
  </code></pre>