如何使用 Javascript 访问从数据库返回的对象
这个函数是从 Javascript 调用的
function searchUser() {
var userName = document.getElementById('UserName').value
$.post("SearchForUser", { userName: userName }, function (UserInfo) {
UserInfo; //How to access the returned UserInfo properties?
});
}
我使用此代码从数据库中获取 UserInfo
public UserInfo SearchForUser(string userName)
{
string password = "nicola";
using (FormValueEntities db = new FormValueEntities())
{
//Query the database for the user
UserInfo userInfo = new UserInfo();
userInfo = db.UserGet(userName, password).FirstOrDefault();
return userInfo;
}
}
UserInfo 具有以下属性:UserName、UserPassword 和 Description