C
C#2y ago
Eistee

❔ Razor Pages Session for revalidating Page Model

Can someone help me to configure the Session for Razor Pages, that I can use TryValidateModel()?
TryValidateModel(this);"
TryValidateModel(this);"
is throwing a InvalidOperationException: Session has not been configured for this application or request.error? I can't find any hint about the online https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.razorpages.pagemodel.tryvalidatemodel?view=aspnetcore-7.0 The debugger is actually stepping over it, but the trace says:
Microsoft.AspNetCore.Http.DefaultHttpContext.get_Session()
Microsoft.Extensions.Internal.PropertyHelper.CallNullSafePropertyGetter<TDeclaringType, TValue>(Func<TDeclaringType, TValue> getter, object target)
Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationEntry.get_Model()
Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.VisitChildren(IValidationStrategy strategy)
Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.VisitComplexType(IValidationStrategy defaultStrategy)
Microsoft.AspNetCore.Http.DefaultHttpContext.get_Session()
Microsoft.Extensions.Internal.PropertyHelper.CallNullSafePropertyGetter<TDeclaringType, TValue>(Func<TDeclaringType, TValue> getter, object target)
Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationEntry.get_Model()
Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.VisitChildren(IValidationStrategy strategy)
Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor.VisitComplexType(IValidationStrategy defaultStrategy)
The server side page Post method looks like this:
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
for (int x = ThirdPartyInformations.Count -1; x >= 0; x--)
{
if (ThirdPartyInformations[x].HiddenEntry == true)
{
ThirdPartyInformations.RemoveAt(x);
}
}

ModelState.Clear();
TryValidateModel(this); // <--
}

if (!ModelState.IsValid ||
....
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
for (int x = ThirdPartyInformations.Count -1; x >= 0; x--)
{
if (ThirdPartyInformations[x].HiddenEntry == true)
{
ThirdPartyInformations.RemoveAt(x);
}
}

ModelState.Clear();
TryValidateModel(this); // <--
}

if (!ModelState.IsValid ||
....
1 Reply
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server