Table of Contents

@Edit.Enable Method in C# Razor (Deprecated)

Warning

This is deprecated but will continue to work for a very long time. For anything new, see Activate 2sxc JavaScript APIs on a Page

Editing or adding data to a 2sxc app requires the UI to have some JS, CSS and context information. This is only loaded/included for editors/admin/super-users, and not available for users with limited permissions.

If you want to enable this for more restricted users - for example when you want to use the 2sxc-form to let users add data - this must be enabled. That's what Edit.Enable(...) is for.

Discover More in the Razor Tutorials

We have an rich series of Razor tutorials. You should really check them out 👍.


How to use

This example shows how you enable the UI using Razor, which will allow public users to create data:

<div>
    @Edit.Enable(api: true, forms: true, context: true, autoToolbar: false)
</div>

This example ensures that

  1. api: basic JS for editing are loaded, allowing you to then run javascript commands like $2sxc(...).run(...)
  2. forms: additional JS is loaded, enabling the standard form dialogs to open
  3. context: the html contains context-information about the app, so that the dialogs actually work - see also edit context
  4. the auto-toolbars are disabled (this would generate a default toolbar if no toolbar was specified)

Usage Notes

This command simply enables editing - but doesn't provide any permissions or show any buttons yet. Here are a few things you must know to get this to work:

  1. remember to set permissions to allow what you want to do (like create new draft items for public users)
  2. Edit.Enable uses named parameters, so you always have to use the api: true syntax
  3. the Edit.Enable won't output anything in the position it's added, because it controls the main wrapper
  4. you must also create a link or toolbar in your code for the public users, as they won't have a button to press otherwise

Read also

History

  1. Introduced in 2sxc 9.30