Hallo Zusammen,
ich arbeite mit dem MVC 3 (Razor) Modell und habe mir ein CustomProfil erstellt. Dazu habe ich in der Webconfig folgendes ergänzt:
<profile inherits="Kano.Models.KanoProfile">
Meine Klasse ist zunächst simpel gehalten:
public class KanoProfile : ProfileBase
{
public string Nachname
{
get
{
return GetPropertyValue("Nachname") as string;
}
set
{
SetPropertyValue("Nachname", value);
}
}
}
Ich versuche nun per Controller ein Profil zu erstellen und zu bearbeiten:
dazu verwendende ich folgende Controller-Methode:
public ActionResult Index()
{
KanoProfile profile = (KanoProfile) KanoProfile.Create(User.Identity.Name);
return View(profile);
}
In meinem Formular kann ich das Profil bearbeiten. Mit dem Submit Button bekomme ich jedoch immer einen Fehler (Fehler weiter unten zu sehen).
Zu meiner Submit Funktion Index(KanoProfile profile) komme ich garnicht erst.
Ich habe bemerkt das es nicht an meinem CustomProfile hängt, denn wenn ich den DefaultProfile verwende bekomme ich die gleiche Meldung.
Wenn ich das Profil im Code bearbeite und speichere funktioniert alles anstandslos.
also z.B. so:
public ActionResult Index()
{
KanoProfile profile = (KanoProfile) KanoProfile.Create(User.Identity.Name);
profile.Nachname = "Schulz";
profile.Save();
return View(profile);
}
Das Profil wird dann auch in die DB geschrieben und wird auch normal geladen. Warum klappt es denn mit dem Binding der View nicht?
Fehler:
Serverfehler in der Anwendung /.
Der Wert darf nicht NULL sein.
Parametername: username
Beschreibung: Unbehandelte Ausnahme beim Ausführen der aktuellen Webanforderung. Überprüfen Sie die Stapelüberwachung, um weitere Informationen über diesen Fehler anzuzeigen und festzustellen, wo der Fehler im Code verursacht wurde.
Ausnahmedetails: System.ArgumentNullException: Der Wert darf nicht NULL sein.
Parametername: username
Quellfehler:
Beim Ausführen der aktuellen Webanforderung wurde einen unbehandelte Ausnahme generiert. Informationen über den Ursprung und die Position der Ausnahme können mit der Ausnahmestapelüberwachung angezeigt werden.
Stapelüberwachung:
[ArgumentNullException: Der Wert darf nicht NULL sein.
Parametername: username]
System.Web.Util.SecUtility.CheckParameter(String& param, Boolean checkForNull, Boolean checkIfEmpty, Boolean checkForCommas, Int32 maxSize, String paramName) +2385917
System.Web.Profile.SqlProfileProvider.FindProfilesByUserName(ProfileAuthenticationOption authenticationOption, String usernameToMatch, Int32 pageIndex, Int32 pageSize, Int32& totalRecords) +39
System.Web.Profile.ProfileBase.RetrieveDates() +85
System.Web.Profile.ProfileBase.get_LastActivityDate() +21
[TargetInvocationException: Der Eigenschaftenaccessor LastActivityDate für das Kano.Models.KanoProfile-Objekt hat folgende Ausnahme verursacht: Der Wert darf nicht NULL sein.
Parametername: username]
System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component) +400
System.Web.Mvc.<>c__DisplayClassb.<GetPropertyValueAccessor>b__a() +18
System.Web.Mvc.ModelMetadata.get_Model() +19
System.Web.Mvc.<Validate>d__1.MoveNext() +154
System.Web.Mvc.<Validate>d__5.MoveNext() +318
System.Web.Mvc.DefaultModelBinder.OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext) +139
System.Web.Mvc.DefaultModelBinder.BindComplexElementalModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Object model) +66
System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +1367
System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +449
System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +317
System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +117
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
System.Web.Mvc.Controller.ExecuteCore() +116
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8969201
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184