【发布时间】:2017-09-05 03:47:15
【问题描述】:
在文本框中获取用户名和电子邮件的值没有问题,但我在获取呈现值时遇到问题,即下拉列表中的角色名。 //控制器类 公共 JsonResult GetByID(int ID) { var user = userRepo.GetAllUsers().Find(x => x.UserID.Equals(ID)); 返回 Json(用户,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
【问题讨论】:
-
错误函数被触发了吗?
-
nope 错误函数没有被触发,因为它适用于文本框
-
你有在 de DDL 中创建的值吗?
-
是的。我确实从数据库中渲染了它
-
@Html.DropDownListFor(model =>model.RoleID, (IEnumerable
)Model.roleList, new {@class= "form-control", @id="roleName"})
标签: c# jquery asp.net ajax asp.net-mvc-5