C# 使用ajax jquery将渲染值设置为下拉列表
在文本框中获取用户名和电子邮件的值没有问题,但我在获取下拉列表中的呈现值(即Rolename)时遇到问题。 //控制器类 public JsonResult GetByID(int-ID) { var user=userRepo.GetAllUsers().Find(x=>x.UserID.Equals(ID)); 返回Json(用户,JsonRequestBehavior.AllowGet); }C# 使用ajax jquery将渲染值设置为下拉列表,c#,jquery,asp.net,ajax,asp.net-mvc-5,C#,Jquery,Asp.net,Ajax,Asp.net Mvc 5,在文本框中获取用户名和电子邮件的值没有问题,但我在获取下拉列表中的呈现值(即Rolename)时遇到问题。 //控制器类 public JsonResult GetByID(int-ID) { var user=userRepo.GetAllUsers().Find(x=>x.UserID.Equals(ID)); 返回Json(用户,JsonRequestBehavior.AllowGet); } <script type="text/javascript"> function g
<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;
}
$(“#roleName”).empty();
$(“#roleName”).append(“”+“”+“”)代码>是否触发了错误函数?没有触发错误函数,因为它对TextBox工作正常您是否在de DDL中创建了值?Rol Admin用户是的。我确实从database@Html.DropDownListFor(model=>model.RoleID,(IEnumerable)model.roleList,新的{@class=“form control”,@id=“roleName”})非常感谢
result:Object
ConfirmPassword:null
Email:"bishal@gmail.com"
Password:null
RoleID:0
RoleName:"Member"
UserID:4
Username:"Bishal"
roleList:null