自定义配置文件提供程序:未找到设置属性“”-MVC3
Posted
技术标签:
【中文标题】自定义配置文件提供程序:未找到设置属性“”-MVC3【英文标题】:Custom Profile Provider : The settings property '' was not found - MVC3 【发布时间】:2012-05-31 21:12:41 【问题描述】:我在尝试编辑/更新用户个人资料时遇到了这个问题。本质上,当用户注册时,他们将布尔调用“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>
任何帮助将不胜感激。
亚历克斯
【问题讨论】:
【参考方案1】:可能会遗漏一些东西,但你使用有什么原因
this.SetPropertyValue()
对于除 base["AuthorizedTeamMember"] = value 之外的所有属性;
【讨论】:
以上是关于自定义配置文件提供程序:未找到设置属性“”-MVC3的主要内容,如果未能解决你的问题,请参考以下文章