1 page for add & edit

Are you guys thinking about using 1 page for Add/Edit instead of the 2 that get generated now?
Depending on a parameter being passed, the title could be different and the submit method could be different (create vs update). As it is I need to maintain 2 pages for almost exactly the same functionality.


We indeed thought of doing it in one page. At that moment Radzen didn’t have support for conditional actions so it wasn’t possible. We decided to keep it that way in order not to break things. You should still be able to implement it in one page if you do it manually though.

How would I accomplish this manually?

  • Grid-Rowselect : open the add page
  • AddPage-Load-Check condition: if parameter execute getbyid and set property
  • Assign the property (set by previous step) to the data property of the form of the add page
  • Form-Even-Savet: also check the parameter to call create or update

Or is there another way?

Yes, the procedure you have describes sounds right. You need to use the Condition property of the actions to execute them only if the parameter is there.

Thank you for sharing your idea. Also there is a solution to achieve this by editing the .cs files (see Why separate Add/Edit? - Radzen.Blazor Components - Radzen) I found a way to do it within the editor (only affecting the json files).

@korchev thank you for any comments to this approach: do you see any caveats?

  1. Modifying the created "Add" button to call the edit page instead of the add page and pass Id = null
  2. Modifying the load() event in the edit page: creating a new object (yes, the entity is a project, we are dealing here, from a table called projects).
  3. Modifying the existing getProjectById event and only do it when the passed parameter was not null:
  4. Modifying the save button on the edit page: add a click event to create the project on the database if the parameter ID was null:

Thank you for letting me know, if this contains unnecessary or faulty steps, your input is much appreciated.

1 Like

Hi @rene, first of all thank you for the idea!

I'm trying to re-use your code but when i try to open the page with ID = null I receive:

Page not found.
Sorry, but there's nothing here!

Do you have any tip?

Does it work if you set ID to a ID that exists?

Hi @tanqan in your second screenshot your condition contains "=", means it sets the parameter value to null instead of checking that its not null. Replace "=" with "!=".

Hi @Gottegubben @rene , that was for sure an error, shame on me!

But it still didn't work. So i tried a workaround setting up ID = -1, instead of null, changin the Condition on:

Convert.ToInt32(${parameters.ID}) != -1

And it worked!

BTW thank you for your precious help.

1 Like