title: Ajax request MVC 4.0 using c#
body: <p>I want to return a record by ajax request</p>
  
  <p>C# code is as:</p>
  
  <pre><code>    [HttpPost]
      public WorkoutsViewModel GetSavedWorkoutTemplate(int WorkoutId)
      {
          return _db.Workouts.Where(w =&gt; w.Id == WorkoutId).Select(w =&gt; new WorkoutsViewModel
          {
              Tag = w.Tags.FirstOrDefault(),
              Name = w.Name,
              MaxEffort = w.MaxEffort,
              Id = w.Id,
              Description = w.Description,
              Compare = w.Compare,
              Category = w.Category
          }).FirstOrDefault();
      } 
  </code></pre>
  
  <p>jQuery code is:</p>
  
  <pre><code>function GetSavedWorkoutTemplate(obj) {      
      $("#Workout").hide();
      var WorkoutId = $(obj).val();
      if (WorkoutId == "") {
          return;
      }
      var dto = { "WorkoutId": WorkoutId };
  
      $.ajax({
          type: "post",
          url: "/MemberWorkout/GetSavedWorkoutTemplate",
          contenttype: "application/json; charset=utf-8",
          data: dto,       
          success: function (result) {
              debugger;
              $("#Workout").show();
          },
          error: function (result) {
              alert("Unable to update status.");
          }
      });
  }
  </code></pre>
  
  <p>Html:</p>
  
  <pre><code> @Html.DropDownList("ddlWorkout", new SelectList(ViewBag.ddlWorkout, "Id", "Name"), "--Select Workout--", new { required = true, onchange = "GetSavedWorkoutTemplate(this);", style = "width:310px" })
  </code></pre>
  
  <p>In success function I got  result as "TheGYM.Web.Models.WorkoutsViewModel" as a string not a model, please correct me what I am doing wrong, I want to return a model.</p>