What is the syntax to wire up Server-Side events (e.g. PreEdit) in .NET?

What is the syntax to wire up Server-Side events (e.g. PreEdit) in .NET?

snafu7x7snafu7x7 Posts: 2Questions: 1Answers: 0

The C# syntax for the editor is really unclear and its difficult to find actual examples that are not in php. This is a basic editor config I built based off the manual/examples on this site. Since everything is chained together I assumed that I could just tack on .PreEdit += (sender, e) => SomeMethod() to the end but that .Data() makes it such that 'editor' variable is no longer the actual editor, its the DtResponse object. I tried decoupling all this chaining but it just errors out with a cryptic js error in the console and I get no data. Can you please provide an example based on the following where a PreEdit even is added to this editor? Thanks.

var editor = new Editor(db, "User", "UserId")
    .Model<User>()
    .Field(new Field("name")
    .Validator(Validation.NotEmpty())
    )
    .Field(new Field("username")
    .Validator(Validation.NotEmpty())
    )
    .Field(new Field("email")
    .Validator(Validation.Email())
    )
    .Field(new Field("isActive")
    .Validator(Validation.Boolean())
    )
    .TryCatch(false)
    .Process(request)
    .Data(); 

Answers

  • allanallan Posts: 61,683Questions: 1Answers: 10,100 Site admin

    You need to split the chain. So you might do:

    var editor = new Editor(db, "User", "UserId")
        .Model<User>()
        .Field(new Field("name")
        .Validator(Validation.NotEmpty())
        )
        .Field(new Field("username")
        .Validator(Validation.NotEmpty())
        )
        .Field(new Field("email")
        .Validator(Validation.Email())
        )
        .Field(new Field("isActive")
        .Validator(Validation.Boolean())
        )
        .TryCatch(false)
        .Process(request);
    
    editor.PreCreate += (sender, e) => ...
    
    var response = editor.Data(); 
    

    See also the examples in the documentation.

    Allan

  • snafu7x7snafu7x7 Posts: 2Questions: 1Answers: 0

    Yep that works fine Allan, thanks for the help!

Sign In or Register to comment.