@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.
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
api
: basic JS for editing are loaded, allowing you to then run javascript commands like$2sxc(...).run(...)
forms
: additional JS is loaded, enabling the standard form dialogs to opencontext
: the html contains context-information about the app, so that the dialogs actually work - see also edit context- 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:
- remember to set permissions to allow what you want to do (like create new draft items for public users)
- Edit.Enable uses named parameters, so you always have to use the
api: true
syntax - the Edit.Enable won't output anything in the position it's added, because it controls the main wrapper
- 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
- Introduced in 2sxc 9.30