title: How to update database with ajax/javascript without refreshing page asp.net mvc
body: <p>I want to change the value of an enumdropdownlist from active to inactive in my database by doing some ajax call <strong>WITHOUT</strong> refreshing my page? How do I do this? javascript method or ajax.beginform? not sure here...</p>
  
  <p>I tried ajax.beginform and the call gets made the to the controller ok, but then it tries to refresh/render a view by returning it as a actionresult. I don't want it to refresh the view because I loose my viewmodel data. I thought ajax.beginform only refreshed what was inside the form? Do I need to perform this in a javascript method instead?
  What do I do to prevent a view from being refreshed/rendered in my action method?</p>
  
  <p>here is my ajax form. If I return a view I loose all the 'Model' view data, so model.statusenabled is null! I don't understand why its null because it's outside of the ajaxform...</p>
  
  <pre><code>@if (Model.StatusEnabled)
        {
            using (Ajax.BeginForm("UpdateStatus", "Student", new AjaxOptions
            {
                HttpMethod = "post",
                OnSuccess = "dotcolor();"
            }))
            {
                @Html.EnumDropDownListFor(model =&gt; model.Status, new { @class = "btn btn-default btn-lg dropdown-toggle", onchange = "this.form.submit();", id = "enumstatus" })
            }
        }
        else
        {
           @Html.EnumDropDownListFor(model =&gt; model.Status, new { @class = "btn btn-default btn-lg dropdown-toggle", disabled = "disabled" })
        }
  </code></pre>
  
  <p>here is my action method</p>
  
  <pre><code>    [HttpPost]
      public ActionResult UpdateStatus()
      {
          //update database
          // don't return view because it gets refreshed
          // and I have to re pass in my viewmodel
          return View("Edit"); 
      }
  </code></pre>
  
  <p>if I change the return type to void in UpdateStatus() it still attemptsto return a view called UpdateStatus. Not what I want.</p>