title: Passing parameters when submitting a form via jQuery in ASP.NET MVC
body: <p>I'm trying to do a form submit to my controller through jQuery Ajax.  The following code works for the most part, however, the ThreadId parameter does not get passed.  If I call the controller directly without using jQuery, it gets passed, but when using jquery, I don't see the ThreadId after form.serialize().  WHat would be the easiest way to pass parameters (like ThreadId) to jQuery form post?</p>
  
  <p>ASPX</p>
  
  <pre><code>&lt;% Html.BeginForm("AddComment", "Home", new { ThreadId = Model.Id },
     FormMethod.Post, new { @id = "AddComment" + Model.Id.ToString(),
     @onsubmit = "javascript:AddComment(this);return false" }); %&gt;
  &lt;%: Html.TextBox("CommentText", "", new { @class = "comment-textbox" })%&gt;
  &lt;input id="Comment" type="submit" name="submitButton" value="Post Comment" /&gt;   
  &lt;% Html.EndForm(); %&gt;
  </code></pre>
  
  <p>JavaScript</p>
  
  <pre><code>    AddComment = function (sender) {
      var form = $(sender);
      var data = form.serialize();
      $.ajax({
          type: "POST",
          url: "/Home/AddComment",
          data: data,
          dataType: "html",
          success: function (response) {
              alert(response);
          },
          error: function (error) {
              alert(error);
          }
      });
      return false;
  };
  </code></pre>
  
  <p>CONTROLLER</p>
  
  <pre><code>    [HttpPost]
          public ActionResult AddComment(string submitButton, Comment comment)
          {
              comment.CreatedDate = DateTime.Now;
              comment.PosterId = LoggedInUser.Id;
  
              _repository.AddComment(comment);
              _repository.Save();
  
              if (Request.IsAjaxRequest())
              {
                  return View("Comment", comment);
              }
              else
                  return RedirectToAction("Index");
          }
  </code></pre>