我在试图编辑/更新用户配置时一直有这个问题。 基本上, 当用户注册时, 他们有一个布尔调用授权团队成员设置假名。 然后他们的团队管理者可以设置真实的用户授权 。
然而,当单击“ 授权” 按钮授权用户时, 我就会发现以下错误 :
The settings property AuthorizedTeamMember was not found.
我四处找了个解决办法,但似乎没有奏效。在HttpPost使用授权玩家的方法之前,它似乎出错了。
< 坚固> 不管在这里, 我的自定义配置文件提供者 : 坚固 >
namespace iConfirm.Models
{
public class TeamPlayer : ProfileBase
{
[Display(Name = "First Name")]
public virtual string FirstName
{
get
{
return (this.GetPropertyValue("FirstName").ToString());
}
set
{
this.SetPropertyValue("FirstName", value);
}
}
[Display(Name = "Last Name")]
public virtual string LastName
{
get
{
return (this.GetPropertyValue("LastName").ToString());
}
set
{
this.SetPropertyValue("LastName", value);
}
}
[Display(Name = "Date Of Birth")]
public virtual string DateOfBirth
{
get
{
return (this.GetPropertyValue("DateOfBirth").ToString());
}
set
{
this.SetPropertyValue("DateOfBirth", value);
}
}
[Display(Name = "Phone Number")]
public virtual string PhoneNumber
{
get
{
return (this.GetPropertyValue("PhoneNumber").ToString());
}
set
{
this.SetPropertyValue("PhoneNumber", value);
}
}
public virtual string TeamId
{
get
{
return (this.GetPropertyValue("TeamId").ToString());
}
set
{
this.SetPropertyValue("TeamId", value);
}
}
public virtual bool AuthorizedTeamMember
{
get
{
return (bool)base["AuthorizedTeamMember"]; //<-- Errors here on post
}
set
{
base["AuthorizedTeamMember"] = value;
}
}
public static TeamPlayer GetProfile(string username)
{
return Create(username) as TeamPlayer;
}
public static List<TeamPlayer> GetProfilesByTeam(int teamId)
{
//var profileList = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All);
var profilesInTeam = Membership.GetAllUsers().Cast<MembershipUser>()
.Select(user => TeamPlayer.Create(user.UserName, true) as TeamPlayer)
.Where(profile => profile.GetPropertyValue("TeamId").ToString().Equals(teamId.ToString()))
.ToList();
return profilesInTeam;
}
}
}
< 加强> 在此为用户授权的代码 : 加强 >
[HttpPost]
public ActionResult AuthorizePlayer(TeamPlayer teamPlayer)
{
teamPlayer.AuthorizedTeamMember = true;
var user = TeamPlayer.GetProfile(teamPlayer.UserName);
user.FirstName = teamPlayer.FirstName;
user.LastName = teamPlayer.LastName;
user.AuthorizedTeamMember = teamPlayer.AuthorizedTeamMember;
user.DateOfBirth = teamPlayer.DateOfBirth;
user.PhoneNumber = teamPlayer.PhoneNumber;
user.Save();
/*TeamPlayer _teamPlayer = TeamPlayer.Create(teamPlayer.UserName) as TeamPlayer;
//var tempProfile = TeamPlayer.Create(teamPlayer.UserName) as TeamPlayer;
_teamPlayer.AuthorizedTeamMember = true;
_teamPlayer.Save();
//Email user that they have been authorized*/
return View("Index");
}
“强”和“强”最后是“强”和“强”
@model iConfirm.Models.TeamPlayer
@{
ViewBag.Title = "AuthorizePlayer";
MembershipUser user = Membership.GetUser(Model.UserName);
}
<h2>AuthorizePlayer</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Authorize the following user?</legend>
@Html.HiddenFor(model => model.AuthorizedTeamMember)
<div class="display-label">
Username
</div>
<div class="display-field">
@Html.DisplayFor(model => model.UserName)
</div>
<div class="display-label">
Full Name
</div>
<div class="display-field">
@Html.DisplayFor(model => model.FirstName) @Html.DisplayFor(model => model.LastName)
</div>
<div class="display-label">
Email
</div>
<div class="display-field">
@user.Email
</div>
<div class="display-label">
Telephone number
</div>
<div class="display-field">
@Html.DisplayFor(model => model.PhoneNumber)
</div>
<div class="display-label">
Date of Birth
</div>
<div class="display-field">
@Html.DisplayFor(model => model.DateOfBirth)
</div>
<p>
<input type="submit" value="Authorize" />
</p>
</fieldset>
}
如有任何帮助,将不胜感激。
亚历克斯