У меня есть функция JavaScript

function getbyID(Id) { $.ajax({ url: "/Home/GetbyID/"   Id, type: "GET", contentType: "application/json;charset=UTF-8", dataType: "json", success: function (result) { $("#UserId").val(result.UserId); $('#FirstName').val(result.FirstName); $('#MiddleName').val(result.MiddleName); $('#LastName').val(result.LastName); $('#ZipCode').val(result.ZipCode); $('#myModal2').show(); $('#btnUpdate').show(); $('#btnSubmit').hide(); } 

Ввиду

 {amp}lt;div class="form-group"{amp}gt; {amp}lt;div class="control-label col-md-2"{amp}gt; {amp}lt;b{amp}gt;First Name{amp}lt;/b{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;div class="col-md-10"{amp}gt; @Html.TextBoxFor(model ={amp}gt; model.FirstName, new { @class = "form-control", id = "FirstName", @placeholder = "First Name" }) @Html.ValidationMessageFor(model ={amp}gt; model.FirstName, "", new { @class = "text-danger", @id = "FirstName" }) {amp}lt;/div{amp}gt; {amp}lt;div class="control-label col-md-2"{amp}gt; {amp}lt;b{amp}gt;Middle Name{amp}lt;/b{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;div class="col-md-10"{amp}gt; @Html.TextBoxFor(model ={amp}gt; model.MiddleName, new { @class = "form-control", @id = "MiddleName", @placeholder = "Middle Name" }) {amp}lt;/div{amp}gt; {amp}lt;div class="control-label col-md-2"{amp}gt; {amp}lt;b{amp}gt;Last Name{amp}lt;/b{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;div class="col-md-10"{amp}gt; @Html.TextBoxFor(model ={amp}gt; model.LastName, new { @class = "form-control", @id = "LastName", @placeholder = "Last Name" }) @Html.ValidationMessageFor(model ={amp}gt; model.LastName, "", new { @class = "text-danger" }) {amp}lt;/div{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;div class="control-label col-md-2"{amp}gt; {amp}lt;b{amp}gt;Zip Code{amp}lt;/b{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;div class="col-md-10"{amp}gt; @Html.TextBoxFor(model ={amp}gt; model.ZipCode, new { @class = "form- control", @id = "ZipCode" }) @Html.ValidationMessageFor(model ={amp}gt; model.ZipCode, "", new { @class = "text-danger" })' 

В контроллере

  public JsonResult GetbyID(int ID) { var q = (from a in obj.Addresses join u in obj.Users on a.UserId equals u.UserId where a.UserId == ID //select a); select new {u.FirstName, u.MiddleName, u.LastName, a.ZipCode }).ToList(); return Json(q, JsonRequestBehavior.AllowGet); } 

Здесь я хочу отображать значения в текстовых полях. Функция работает успешно и отображает результат в функции (результат), когда я отлаживаю код, но не отображается в текстовом поле. Как решить эту проблему.?

Пожалуйста, попробуйте этот код, я обновил код

У меня есть функция JavaScript

  {amp}lt;script{amp}gt; function getbyID(Id) { try { $.ajax({ url: "/Home/GetbyID/"   Id, type: "GET", contentType: "application/json;charset=UTF-8", dataType: "json", success: function (result) { $(".jsUserId").val(result.UserId); $('.jsFirstName').val(result.FirstName); $('.jsMiddleName').val(result.MiddleName); $('.jsLastName').val(result.LastName); $('.jsZipCode').val(result.ZipCode); } }); } catch (e) { console.log("Error : getbyID : "   e.message); } } {amp}lt;/script{amp}gt; 

В просмотре я сделал

  {amp}lt;div class="form-group"{amp}gt; {amp}lt;div class="control-label col-md-2"{amp}gt; {amp}lt;b{amp}gt;First Name{amp}lt;/b{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;div class="col-md-10"{amp}gt; @Html.HiddenFor(model ={amp}gt; model.UserId, new { @class = "form-control jsUserId", id = "UserId"}) @Html.TextBoxFor(model ={amp}gt; model.FirstName, new { @class = "form-control jsFirstName", id = "FirstName", @placeholder = "First Name" }) @Html.ValidationMessageFor(model ={amp}gt; model.FirstName, "", new { @class = "text-danger", @id = "FirstName" }) {amp}lt;/div{amp}gt; {amp}lt;div class="control-label col-md-2"{amp}gt; {amp}lt;b{amp}gt;Middle Name{amp}lt;/b{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;div class="col-md-10"{amp}gt; @Html.TextBoxFor(model ={amp}gt; model.MiddleName, new { @class = "form-control jsMiddleName", @id = "MiddleName", @placeholder = "Middle Name" }) {amp}lt;/div{amp}gt; {amp}lt;div class="control-label col-md-2"{amp}gt; {amp}lt;b{amp}gt;Last Name{amp}lt;/b{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;div class="col-md-10"{amp}gt; @Html.TextBoxFor(model ={amp}gt; model.LastName, new { @class = "form-control jsLastName", @id = "LastName", @placeholder = "Last Name" }) @Html.ValidationMessageFor(model ={amp}gt; model.LastName, "", new { @class = "text-danger" }) {amp}lt;/div{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;div class="control-label col-md-2"{amp}gt; {amp}lt;b{amp}gt;Zip Code{amp}lt;/b{amp}gt; {amp}lt;/div{amp}gt; {amp}lt;div class="col-md-10"{amp}gt; @Html.TextBoxFor(model ={amp}gt; model.ZipCode, new { @class = "form- control jsZipCode" , @id = "ZipCode" }) @Html.ValidationMessageFor(model ={amp}gt; model.ZipCode, "", new { @class = "text-danger" }) {amp}lt;/div{amp}gt; 

В контроллере

 public JsonResult GetbyID(int ID) { var q = (from a in obj.Addresses join u in obj.Users on a.UserId equals u.UserId where a.UserId == ID //select a); select new {u.FirstName, u.MiddleName, u.LastName, a.ZipCode }).FirstOrDefault(); return Json(q, JsonRequestBehavior.AllowGet); }