title: How to insert data by a partial view in MVC
body: <p>I want to insert data using partial view for this action method which I have mentioned below.</p>
  
  <p>The problem is that when I submit the Form it doesn't gave me any response. </p>
  
  <p>What can I do with that post the comments and redirect to this page when comment is post?</p>
  
  <p>And my partial view is located in a shared folder.</p>
  
  <pre><code>    [HttpPost]
      [ValidateAntiForgeryToken]
      public JsonResult Comments([Bind(Include = "CommentId,UserComments,UserId")] Comment comment)
      {
          if (ModelState.IsValid)
          {
              db.Comments.Add(comment);
              db.SaveChanges();
              return Json(comment, JsonRequestBehavior.AllowGet);
          }
          ViewBag.UserId = new SelectList(db.UserAccounts, "UserId", "FirstName", comment.UserId);
          return Json(JsonRequestBehavior.AllowGet);
      }
  </code></pre>
  
  <p>Rendering partial view in layout.</p>
  
  <pre><code> @Html.Partial("_Comments", new OnlineTaxiReservationSystem.Models.Comment())
  </code></pre>
  
  <p>and the partial view is here: </p>
  
  <pre><code>  @model OnlineTaxiReservationSystem.Models.Comment
  
   &lt;script type="text/javascript"&gt;
  $(document).on('click', '.btnSubmit', function () {
      $.ajax({
          url: '@Url.Action("Comments", "Home")',
          cache: false,
          async: true,
          data: {
              //put the data that you want to save from the partial here
              UserId: $('#userId').val(),
              UserComments: $('#content').val()
          },
          success: function (_result) {
              window.location.href = "Home/Index";
          }
      });
  });
  </code></pre>
  
  <p></p>
  
  <pre><code>  @if (Session["user"] != null)
       {
     using (Html.BeginForm())
     {
        @Html.AntiForgeryToken()
  
      &lt;div class="form-horizontal"&gt;
          &lt;h4&gt;Your Feedback&lt;/h4&gt;
          &lt;hr /&gt;
          @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  
          &lt;div class="form-group" style="margin-left: 9%"&gt;
              @Html.LabelFor(model =&gt; model.UserId, "User Name", htmlAttributes: new { @class = "control-label col-md-2" })
              @*@Html.Label(Session["UserName"].ToString(), htmlAttributes: new { @class = "control-label label-primary col-md-1" })*@
              &lt;div class="col-md-4"&gt;
                  @Html.Editor("UserId", null, new { htmlAttributes = new { @class = "form-control", @id = "userId" } })
                  @Html.ValidationMessageFor(model =&gt; model.UserId, "", new { @class = "text-danger" })
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.UserComments, htmlAttributes: new { @class = "control-label col-md-1" })
              &lt;div class="col-lg-12"&gt;
                  @Html.TextAreaFor(model =&gt; model.UserComments, new { htmlAttributes = new { @class = "form-control", @id = "content"} })
                  @Html.ValidationMessageFor(model =&gt; model.UserComments, "", new { @class = "text-danger" })
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              &lt;div class="col-md-offset-1 col-md-10"&gt;
                  &lt;input type="submit" value="Submit" id="btnSubmit" class="btn btn-primary" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
    }
  
    &lt;div&gt;
      @Html.ActionLink("Back to List", "Index")
    &lt;/div&gt;
    }
  </code></pre>