WebVella / WebVella-ERP

Free and open-source pluggable ERP and CRM software based on ASP.NET Core 8, RazorPages and PostgreSQL . Targets Linux or Windows as host OS.
https://webvella.com/documents/developer/introduction/overview
Other
1.24k stars 465 forks source link

Is there a way to add local properties to a page that can be accessed on page hooks #209

Closed GittingGudAtIT closed 1 month ago

GittingGudAtIT commented 1 month ago

I'm just getting into your software. It is pretty easy to setup pages with the generated body editor but I have no idea how i can create pages with it when there is no record or data source to map.

The problem is: I'm creating a page that downloads data from the internet and directly imports them into the database. So I tried to create a form where I linked my custom page hook (IPageHook). And a button submits this form. So far so good page hook is working correctly but I have no Idea where I could get the values of defined Fields within a BaseErpPageModel.

Do I have to create a custom body instead or am I missing something?

bzashev commented 1 month ago

Hey, I just worked today on this for a project. You can find the complete request in BaseErpPageModel pageModel The form is pageModel.Request.Form - this is the standard ASP form in other words a dictionary.

if (form.ContainsKey("customer_id") && !string.IsNullOrWhiteSpace(form["customer_id"].ToString()))
{
    if (Guid.TryParse(form["customer_id"].ToString(), out Guid outGuid))
    {
        customerId = outGuid;
    }
}

this is how I deal with it. This is done OnPost.

Another good tip is that OnGet you can preinit the form values by setting them up in the Record. Example:

EntityRecord record = new EntityRecord();
record["customer_id"] = SOME_GUID
pageModel.DataModel.SetRecord(record);

Hope this helps

GittingGudAtIT commented 1 month ago

Thank you @bzashev, that totally helped!