I'm wondering if there is a good example of how to edit ASP.NET Profile settings in MVC using model binding.
Currently I have:
- a custom ProfileCommon class derived from ProfileBase.
- a strongly typed view (of type ProfileCommon)
- get and post actions on the controller that work with ProfileCommon and the associated view. (see code below).
Viewing the profile details works - the form appears all the fields are correctly populated.
Saving the form however gives exception:System.Configuration.SettingsPropertyNotFoundException: The settings property 'FullName' was not found.
Thinking about this it makes sense because the model binding will be instantiating the ProfileCommon class itself instead of grabbing the one of the httpcontext. Also the save is probably redundant as I think the profile saves itself automatically when modified - an in the case, probably even if validation fails. Right?
Anyway, my current thought is that I probably need to create a separate Profile class for the model binding, but it seems a little redundant when I already have a very similar class.
Is there a good example for this around somewhere?
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Edit()
{
return View(HttpContext.Profile);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(ProfileCommon p)
{
if (ModelState.IsValid)
{
p.Save();
return RedirectToAction("Index", "Home");
}
else
{
return View(p);
}
}