I searched and tried my problem and I cannot find a solution, I want to know if anyone can help me fix my code.
I have the ability to edit users.
@model MembershipUser
@{
ViewBag.Title = "Edit";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<div class="editor-label">
Username:
</div>
<div class="editor-field">
@Html.DisplayFor(model => model.UserName)
</div>
<div class="editor-label">
Email:
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Email)
</div>
<div class="editor-label">
Password:
</div>
<div class="editor-field">
@Html.DisplayFor(model => model.Password)
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
And then in the controller the action can get information about the user.
[Authorize(Roles = "Admins")]
public ActionResult Edit(string username)
{
var usu = Membership.GetUser(username);
return View(usu);
}
And one more can update the user.
[Authorize(Roles = "Admins")]
[HttpPost]
public ActionResult Edit(MembershipUser umtoupdate)
{
MembershipUserCollection iduser = Membership.GetAllUsers();
if(umtoupdate.Password != umtoupdate.ConfirmPassword)
{
alert = "Password dont match!";
return View("Users", "Admin");
}
else {
foreach (MembershipUser um in iduser) {
if (um.UserName == umtoupdate.UserName) {
Membership.DeleteUser(um.UserName, true);
MembershipCreateStatus createStatus;
Membership.CreateUser(umtoupdate.UserName,
umtoupdate.Password,
umtoupdate.Email,
umtoupdate.PasswordQuestion,
umtoupdate.AnswerQuestion, true, null, out createStatus);
}
}
}
return View("Details", umtoupdate.UserName);
}
And in this class, I defined one constructor that creates a list to do other things (I suppose because it tells me something about the constructor without parameters).
public AdminController()
{
foreach (MembershipUser member in iduser) {
UserEntity entity2 = new UserEntity();
entity2.Username = member.UserName;
entity2.Roles = "Users";
entity2.Email = member.Email;
for (int i = 1; i < iduser.Count; i++)
{
entity2.ID_client = i;
}
_entities.Add(entity2);
}
And then, I want to change the user, I can go to the first view (where you can edit the information), but when I try to save the updated information and go to the second view to update the user, tell me
"[MissingMethodException , .)
- , ? Edit (string) , , , .
.
, , ! MemberhipUser (, MyUser, , ),
public ActionResult Edit(MyUser umtoupdate) {...}
, , im MemberhipUser MyUser,
[Authorize(Roles = "Admins")]
public ActionResult Edit(string username)
{
var usu = Membership.GetUser(username);
return View(usu);
}
membeship , MyUser.GetUser, !
, ?
.