I am trying to create a form for updating user info. I am using typed view for model class User:
public class User : MembershipUser, IEntity
{
public virtual int Id { get; set; }
public virtual string Username { get; set; }
public virtual string Password { get; set; }
public virtual string Name { get; set; }
public virtual string Surname { get; set; }
public virtual Role Role { get; set; }
public virtual string ProfileImage { get; set; }
public virtual string About { get; set; }
}
The view looks like this:
using (Html.BeginForm("SaveUser", "BlogUser", FormMethod.Post, new { @class = "form-horizontal", enctype = "multipart/form-data" }))
{
<div class="form-group">
@Html.HiddenFor(x => x.Id)
@Html.HiddenFor(x => x.ProfileImage)
@Html.HiddenFor(x => x.UserName)
@Html.HiddenFor(x => x.Password)
@Html.HiddenFor(x => x.Role)
<div class="col-sm-10">
<label>Jméno</label>
</div>
<div class="col-sm-10">
@Html.TextBoxFor(x => x.Name, new { @class = "form-control" })
@Html.ValidationMessageFor(x => x.Name)
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<label>Příjmení</label>
</div>
<div class="col-sm-10">
@Html.TextBoxFor(x => x.Surname, new { @class = "form-control" })
@Html.ValidationMessageFor(x => x.Surname)
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<label>Profilový obrázek</label>
</div>
<div class="col-sm-10">
<input type="file" name="picture" />
@if (!String.IsNullOrEmpty(Model.ProfileImage))
{
<img src="@Url.Content("~/Upload/UserImages/" + Model.ProfileImage)" />
}
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<label>Něco o mně</label>
</div>
<div class="col-sm-10">
@Html.TextAreaFor(x => x.About, new { @class = "form-control formatedText", @rows = 20 })
@Html.ValidationMessageFor(x => x.About)
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<button type="submit" class="btn btn-primary btn-lg btn-block">Uložit</button>
</div>
</div>
}
I am getting right user, i have prefilled columns with right details, but after submit it throws exception [Argument Exception “Item with Same Key has already been added”]. I wont even trigger the SaveUser() controller method, so I could atleast debug it. I cant figure out where the problem is. Can you help me?