Hi, I have a custom page with a form. Everytime I click submit button, an exception thrown
System.NullReferenceException: 'Object reference not set to an instance of an object.'
Piranha.AspNetCore.Models.SinglePage
I understand that form post method also refresh the page but why it does it return null in this case because I can refresh on browser without problem.
The most common mistake is that you鈥檙e posting directly to the Razor Page or Controller and not to the permalink of the page. You need to post to the permalink for the middleware to kick in and the page data to be loaded properly.
Best regards
Thank you for your quickly reply!!!
Im using Razor Page. According to your above answer, I have modified <form action="@Model.Data.Permalink" method="post"> ... But it returns http error 400.
That's a good start! However if we look at the code for SinglePage<T> it automatically loads the model on a GET request, see here:
You need to load the page model in your Post handler. See the post action in SinglePageWithComments<T> as an example:
Best regards
Thank you so much!!! I have made it works like your suggestion.
Also, I would like to add an additional function to Piranha Manager just like Comment moderating. What should I do?
Hi there! We have a project template for creating a module with embedded manager interface that you can look at if you want to package your new manager views into it's own project. You can create a new module project by calling:
~
dotnet new piranha.module
~
assuming that you have our project templates installed.
Regards