Search code examples
c#sitefinitysitefinity-10

Sitefinity Custom MVC Widget edit menus


I created a Sitefinity widget in MVC (2 views, a controller, and a model) and it works as expected.

Except for the edit menu after I drag the widget into the page. All of my fields in the edit view are text inputs, and I'm not sure how to affect this.

One of my fields should be a dropdown with values from an Enum - this enum lists the names of both of my views, and is used by the controller to pick which one I want to render. When I open the edit view for the widget, it defaults to the first value in my enum and everything renders properly, but I'd like this to be a dropdown instead of a text input requiring magic string knowledge on the user's part.

Another of my fields chooses a page to link to, which is used in the action attribute of a form inside my widget. This again works, but is simply a string text field, where I would like to use the built-in Sitefinity page selector many of the "native" widgets use, if possible.

So the short version is: Where/How do I affect what type of input shows up in the "edit" view of a widget once it's added to a page?


Solution

  • In terms of Sitefinity, the view, when you editing widget settings is "Widget designer".

    Official documentation if you using Feather: https://docs.sitefinity.com/feather-create-custom-designer-views

    Documentation for non-Feather users: https://docs.sitefinity.com/for-developers-create-a-simple-widget-designer

    Simple example in your case if you want to use dropdown instead of input:

    1. Create DesignerView.Simple.cshtml in your View/<ControllerName> folder
    2. Add into this file: <select sf-model="properties.Content.PropertyValue"><option>abc</option><option>xyz</option></select> where Content is your property name
    3. And it will render dropdown if you will edit this widget in backend.

    Links: