title: Is there any help to save data to database?
body: <p>I am trying to save or insert data into my database where my table is Purchase. But it is not saving any data to my table, and also not showing any error. At first i don't know why Save button is not clicking. Here is my ajax method where i am posting to controller for saving data. here is my ajax code. Please Help me..</p>
  
  <pre><code> $('#btnSave').click(function () {
                   var pform = $('frmpm');
                   var llink = '/Purchases/PurchaseMaster/';
                   var pm = {};
                   $.each(pform.serializeArray(), function () {
                       pm[this.name] = this.value;
                   });
                   $.ajax({
                       url: llink,
                       async: false,
                       cache: false,
                       type: 'POST',
                       data: pm,
                       success: function (data) { },
                       error: function (data) {
                           alert(data.msg);
                       }
                   });
               });
  </code></pre>
  
  <p>Here is my Controller Where is I am Trying to save data...it is not showing any error or success message..</p>
  
  <pre><code>[HttpPost]
          public ActionResult PurchaseMaster(Purchase pm)
          {
              try
              {
                  if (ModelState.IsValid)
                  {
                      db.Insert("Purchase", "PId", pm);
                      return Json(new { msg = "Purchase has been saved Successfully." });
                  }
                  return Json(new { msg = "Purchase Is InValid." });
              }
              catch
              {
                  return Json(new { msg = "Sorry ! Something wrong with your Purchase Master." });
              }
          }
  </code></pre>
  
  <p>And this is my index view </p>
  
  <pre><code>  @using (Html.BeginForm("Index", "Purchases", FormMethod.Post, new { @id="frmpm"}))
  {
      @Html.ValidationSummary(true)
  
      &lt;fieldset&gt;
          &lt;legend&gt;Purchase&lt;/legend&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.PId)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.PId)
              @Html.ValidationMessageFor(model =&gt; model.PId)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.Label("Purchase No")
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.PNo)
              @Html.ValidationMessageFor(model =&gt; model.PNo)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.Label("Purchase Date")
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.PDate)
              @Html.ValidationMessageFor(model =&gt; model.PDate)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.Label("SuppLier")
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.SupId)
              @Html.ValidationMessageFor(model =&gt; model.SupId)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.Label("Supply Area")
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.SupArea)
              @Html.ValidationMessageFor(model =&gt; model.SupArea)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.Label("Purchase Amount")
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.PAmount)
              @Html.ValidationMessageFor(model =&gt; model.PAmount)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.Label("Purchase Mode")
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.DropDownList("PMode")
              @Html.ValidationMessageFor(model =&gt; model.PMode)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.Label("Cheque No")
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.ChqNo)
              @Html.ValidationMessageFor(model =&gt; model.ChqNo)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.BankAcc)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.BankAcc)
              @Html.ValidationMessageFor(model =&gt; model.BankAcc)
          &lt;/div&gt;
           &lt;div id="splist" &gt;
          &lt;/div&gt;
          @Html.Action("Purchaseitem")
           &lt;p&gt;
              &lt;input id="btnSave" type="button" value="Save" /&gt;
          &lt;/p&gt;
      &lt;/fieldset&gt;
  }
  </code></pre>
  
  <p>I think Problem Is here Cause it is not executing..</p>
  
  <pre><code> db.Insert("Purchase", "PId", pm);
  </code></pre>