ユーザー プロファイルを編集/更新しようとすると、この問題が発生します。基本的に、ユーザーが登録すると、bool 呼び出し 'AuthorizedTeamMember' が false に設定されます。その後、チーム マネージャーはそれを true に設定して、ユーザーを承認できます。
ただし、「承認」ボタンをクリックしてユーザーを承認すると、次のエラーが発生します。
The settings property 'AuthorizedTeamMember' was not found.
解決策を見つけるために周りをよく見ましたが、何も機能していないようです。HttpPost の「AuthorizePlayer」メソッドにヒットする前にエラーになるようです。
とにかく、ここに私のカスタムプロファイルプロバイダーがあります:
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>
}
どんな助けでも大歓迎です。
アレックス