English 中文(简体)
自定义配置提供者 : 未找到设置属性 - MVC3
原标题:Custom Profile Provider : The settings property was not found - MVC3

我在试图编辑/更新用户配置时一直有这个问题。 基本上, 当用户注册时, 他们有一个布尔调用授权团队成员设置假名。 然后他们的团队管理者可以设置真实的用户授权 。

然而,当单击“ 授权” 按钮授权用户时, 我就会发现以下错误 :

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>
}

如有任何帮助,将不胜感激。

亚历克斯

问题回答

可能遗漏了什么东西......但你使用它有原因吗?

这里。 etPropertyValue ()

除基底[“授权的团队成员”]=值外,所有属性均适用;





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签