Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
Set the rendered value to the dropdown using ajax jquery

There is no problem in getting the value in textbox for username and email but i am having the problem in getting the rendered value i.e Rolename in the dropdown list. //Controller class public JsonResult GetByID(int ID) { var user = userRepo.GetAllUsers().Find(x => x.UserID.Equals(ID)); return Json(user, JsonRequestBehavior.AllowGet); }

<script type="text/javascript">
function getByID(UserID)
{
    debugger;
    $('.uname').css('border-color', 'green');
    $('.mail').css('border-color', 'green');
    $.ajax({

        url: "../Easyshop/User/GetByID/" + UserID,
        type: "Get",
        contentType: "application/json;charset=UTF-8",
        dataType: "json",
        success: function (result)
        {
            debugger;
            $('#Username').val(result.Username);
            $('#Email').val(result.Email);
            $('#roleName').val(result.RoleName);
        },
        error: function (errormessage)
        {
            alert(errormessage.responseText);
        }
    });
    return false;
}

result:Object
ConfirmPassword:null
Email:"bishal@gmail.com"
Password:null
RoleID:0
RoleName:"Member"
UserID:4
Username:"Bishal"
roleList:null
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

  1. For Single value use below syntax

$("#roleName").empty();
$("#roleName").append('<option value="' + result.RoleName + '">' + "" + '</option>');

  1. If you have to load list of values

 $("#roleName").empty();

 $("#roleName").append('<option value="' + 0 + '">' +"" + '</option>');

 $.each(data, function (i, RoleName) {

     $("#roleName").append('<option value="' + RoleName.Value + '">' +

     RoleName.Text + '</option>');
  });

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!