title: How to get value from JSON and show it in a textbox?
body: <p>I want to parse value from JSON type data and show it in a textbox. I have managed to passed json data from <strong>Controller</strong> to <strong>View</strong>. But I just can't show it in a textbox in my <strong>View</strong>. I have tried to show the <em>value</em> using <em>alert</em>, but it shows only <strong>[object][Object]</strong></p>
  
  <p><strong>View</strong></p>
  
  <pre><code>    &lt;div class="form-group"&gt;
          @Html.LabelFor( model =&gt; model.StudentRegNo, htmlAttributes: new { @class = "control-label col-md-2" } )
          &lt;div class="col-md-10"&gt;
              @Html.DropDownListFor( model =&gt; model.StudentRegNo, new SelectList( ViewBag.StudentListForDDL, "Value", "Text" ), "--SELECT--", new { @class = "form-control", @id = "studentReg" } )
              @Html.ValidationMessageFor( model =&gt; model.StudentRegNo, "", new { @class = "text-danger" } )
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor( model =&gt; model.StudentName, htmlAttributes: new { @class = "control-label col-md-2" } )
          &lt;div class="col-md-10"&gt;
              @Html.TextBoxFor( model =&gt; model.StudentName, new { @class = "form-control", @id = "StudentName" } )
          &lt;/div&gt;
      &lt;/div&gt;
  @section Scripts {
  &lt;script src="~/Scripts/jquery-2.2.0.js"&gt;&lt;/script&gt;
  &lt;script src="~/Scripts/jquery.validate.js"&gt;&lt;/script&gt;
  &lt;script src="~/Scripts/jquery.validate.unobtrusive.js"&gt;&lt;/script&gt;
  @*@Scripts.Render( "~/bundles/jqueryval" )*@
  &lt;script&gt;
      $(document).ready(function () {
          $("#studentReg").change(function () {
              var reg = $("#studentReg").val();
              var json = { studentReg: reg };
              $.ajax({
                  type: "POST",
                  url: '@Url.Action( "GetStudentByRegNo","Result")',
                  contentType: "application/json; charset=utf-8",
                  data: JSON.stringify(json),
                  success: function (data) {
                      //$.each(data, function (key, value) {
                      //    //var name = value.StudentName;
                      //    alert(key.StudentName);
                      //});
                      alert(data);
                  }
              });
          });
      });
  &lt;/script&gt;}
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>public class ResultController : Controller {
      private ResultManager objResultManager = new ResultManager();
      // GET: Result
      public ActionResult ViewResult() {
          var studentList = objResultManager.GetListOfStudents();
          List&lt;SelectListItem&gt; studetListItems = new List&lt;SelectListItem&gt;();
          foreach (Student objStudent in studentList) {
              studetListItems.Add(new SelectListItem {Value = objStudent.StudentRegNo, Text = objStudent.StudentRegNo});
          }
          ViewBag.StudentListForDDL = studetListItems;
          return View();
      }
      //GET Student By Registration Number
      public JsonResult GetStudentByRegNo(string studentReg) {
          Student objStudent = objResultManager.GetStudentByRegNo(studentReg);
          return Json(objStudent,JsonRequestBehavior.AllowGet);
      }
  }
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <pre><code>public class Student {
      public string StudentRegNo { get; set; }
      public string StudentName { get; set; }
      public string StudentEmail { get; set; }
      public string StudentContactNo { get; set; }
      public DateTime StudentRegDate { get; set; }
      public string StudentAddress { get; set; }
      public string Department { get; set; }
  }
  </code></pre>
  
  <p>What am I doing wrong here? </p>
  
  <p>Thanks in advance.</p>