This code
@Html.TextBoxFor(m => m.UserName, new { @class = "validate[required]", disabled = "disabled", value = ViewBag.user[0].UserName }) @Html.ValidationMessage("usernameVal", "*")
trows an exception when it get to ViewBag.user[0].UserName
Exception:
The best overloaded method match for ‘System.Web.Security.MembershipUserCollection.this[string]’ has some invalid arguments
Action:
public ActionResult EditUser()
{
//Resgata username do registro
string user = Request.QueryString["username"];
try
{ //Se nome foi resgatado
String.IsNullOrEmpty(user)
MembershipUserCollection muc = Membership.FindUsersByName(user);
ViewBag.user = muc;
return PartialView();
}
catch (Exception e)
{
return Content("Erro: " + e);
}
}
In your view, you are accessing the collection using the integer index
As the Exception states, to access the MembershipUserCollection you need to provide a string argument.
See the documentation – http://msdn.microsoft.com/en-us/library/system.web.security.membershipusercollection.item.aspx
Gets the membership user in the collection referenced by the specified user name.
Instead of returning a collection from your Controller method, just return the single MembershipUser object
In your controller:
In your view:
Replace value = ViewBag.user[0].UserName with value = ViewBag.user.UserName