Radzen Professional is now 20% off until January 4th 2019! Learn more

Customizing generated application

Various parts of the generated application by Radzen can be customized without breaking the app continuous regeneration. To do this you can use your favorite code editor, for example Visual Studio Code.

Code generation ignore list

By default Radzen generates code for your Radzen application pages and data sources (Angular components, OData controllers etc). If you want to tweak the code you can do so in one of two ways:

  1. By following the Radzen extensibility rules and writing your custom code in the provided extensibility hooks listed later in this article.
  2. By adding the file(s) you want to modify in Radzen’s code generation ignore list. This section shows how this is done.

The Code generation ignore list is advanced feature that should be used only if none of the provided extensibility hooks would work for you.

You can add a certain file, list of files or entire directories to Radzen’s code generation ignore list by going to the application settings (the three dots button in the top right corner). Then add a list of files or directories separeated with a new line in the Code generation ignore list textbox.

The ignore list follows the gitignore conventions. Here are a few examples:

client\src\app\home

Stop generating files in the client\src\app\home directory.

client\src\app\home
client\src\app\*product

Ignore the client\src\app\home directory and all directories that look like client\src\app\*product e.g. client\src\app\add-product, client\src\app\edit-product.

server\Startup.cs

Ignore particular file.

Here is a quick FAQ about ignored files:

What happens to ignored files

Radzen will not longer output code to files that match the ignore list. For example if you ignore the client\src\app\home directory and you make changes in any of those files e.g. home.component.html those changes will persist. If you later modify that page from Radzen’s designer you will not see any code generated for those changes. The changes will be persisted in the metadata though.

Will Radzen preview my changes in design time

Radzen uses the metadata (stored in the meta directory) to generate the design time experience. This is why any custom modifications to the generated code will not be previewed.

Remove files from ignore list

Remove the ignore rule that matches those files from the application setting and run the application. Radzen will update the files that were in the ignore list.

Customizing the Angular code

The code of each page in the generated Angular application is separated in three files. [PAGE-NAME].component.ts, [PAGE-NAME].component.html and [PAGE-NAME]-generated.component.ts. You can add additional code and/or other customizations to [PAGE-NAME].component.ts file only. For example with custom code please visit Custom Component article in our documentation.

Customizing the ASP.NET Core code

When you add Microsoft SQL Server, MySQL and/or PostgreSQL data-source, Radzen will generate ASP.NET Core server-side application. Pages are represented by MVC Controllers and you can customize every controller read, add, update and delete operation using C# partial classes and methods.

public partial class CategoriesController
{
    partial void OnCategoriesRead(ref IQueryable<Category> items)
    {
        //
    }

    partial void OnCategoryDeleted(Category item)
    {
        //
    }

    partial void OnCategoryUpdated(Category item)
    {
        //
    }

    partial void OnCategoryCreated(Category item)
    {
        //
    }
}
Public Partial Class CategoriesController
    Private Partial Sub OnCategoriesRead(ByRef items As IQueryable(Of Category))
    End Sub

    Private Partial Sub OnCategoryDeleted(ByVal item As Category)
    End Sub

    Private Partial Sub OnCategoryUpdated(ByVal item As Category)
    End Sub

    Private Partial Sub OnCategoryCreated(ByVal item As Category)
    End Sub
End Class

The execution of Microsoft SQL Server stored procedures can be extended as well. Please visit Stored procedure default parameter value article.

For example how to invoke custom server-side method please visit Invoke custom server-side method article.

For example how to extend server authenticated please visit Authentication and Authorization article.

Custom server validation

You can add custom server validation using partial classes/methods for Delete, Update and Create.

public partial class CategoriesController
{
    partial void OnCategoryDeleted(Category item)
    {
    }

    partial void OnCategoryUpdated(Category item)
    {
        if (item.CategoryName == "Invalid")
        {
            throw new Exception("Custom error message");
        }
    }

    partial void OnCategoryCreated(Category item)
    {
        //
    }
}
Public Partial Class CategoriesController
    Private Partial Sub OnCategoryDeleted(ByVal item As Category)
    End Sub

    Private Partial Sub OnCategoryUpdated(ByVal item As Category)
        If item.CategoryName Is "Invalid" Then
            Throw New Exception("Custom error message")
        End If
    End Sub

    Private Partial Sub OnCategoryCreated(ByVal item As Category)
    End Sub
End Class

Then to keep the edit form visible you should update the canEdit page property: from !(result.status == 400) to result.status != 400 || result.error.

To display the custom message update the Message property of the Notify action. Set it to Unable to update: ${result.error.message}

We are here for you

Making our users happy is always a priority for us.