title: How to change the value in Html.TextBox for using Jquery and Json?
body: <p>In the create view what i am trying to do is when you choose a name from the dropdown list to fill the Login html.TextBoxFor automatically with his details.</p>
  
  <p>Currently the Login textbox remains empty when i choose a person from dropdown list.</p>
  
  <p>So i ve got my json object and tested as well my sql which is fine so i suppose the issue must be somewhere in jquery.</p>
  
  <p>I would be glad if you could help me find the error.</p>
  
  <p><strong>View :</strong></p>
  
  <pre><code>@using (Html.BeginForm()) {
      @Html.AntiForgeryToken()
      @Html.ValidationSummary(true)
          &lt;fieldset&gt;
              &lt;legend&gt;User&lt;/legend&gt;
              &lt;div class="editor-label"&gt;@Html.LabelFor(model =&gt; model.UserLogin)&lt;/div&gt;
              &lt;div class="editor-field"&gt;@Html.TextBoxFor(model =&gt; model.UserLogin, new {id ="LoginId" })
  
              @Html.ValidationMessageFor(model =&gt; model.UserLogin)&lt;/div&gt;
              &lt;div class="editor-label"&gt;@Html.LabelFor(model =&gt; model.UserFullName)&lt;/div&gt;
              &lt;div class="editor-field"&gt;@Html.DropDownList("UserFullName", ViewBag.UserFullName as SelectList, "Select a User", new { id = "UserID" })
  
              @Html.ValidationMessageFor(model =&gt; model.UserFullName)&lt;/div&gt;
              &lt;p&gt;
                  &lt;input type="submit"
                         value="Create" /&gt;
              &lt;/p&gt;
          &lt;/fieldset&gt; }
          &lt;div&gt;@Html.ActionLink("Back to List", "Index")&lt;/div&gt;
          &lt;script type="text/javascript"&gt;
          $('#UserID').on('change', function () {
              $.ajax({
                  type: 'POST',
                  url: '@Url.Action("GetUserForm")',
              data: { FullName: $('#UserID').val() },
              success: function (results){
                  var login = $('#LoginId');
                  login.empty();
  
                  $.each(results, function () 
                  {
                      login.val(this.ID).text(this.Value);
                  });
              }});
          });
          &lt;/script&gt;
  </code></pre>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>public ActionResult Create()
  {
      var names = StaffDB.StaffData.AsEnumerable().Select(s =&gt; new
      {
          ID = s.ID,
          FullName = string.Format("{0} {1}", s.Forename1, s.Surname)
      }).ToList();
      if(ModelState.IsValid)
      {
          db.Users.Add(user);
          db.SaveChanges();
          return RedirectToAction("Index");
      }
      ViewBag.UserFullName = new SelectList(names, "FullName", "FullName", user.UserFullName);
      return View(user);
  }
  
  [HttpPost]
  public JsonResult GetUserForm(string FullName)
  {
      //pseudo code
      var data = from s in StaffDB.StaffData
                 where s.Forename1 + ' ' + s.Surname == FullName
                 select new
                 {
                     Value = s.Login,
                     ID = s.ID
                 };
      return Json(data);
  }
  </code></pre>