+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / What is the proper way to set a default value for an MVC widget's property?

What is the proper way to set a default value for an MVC widget's property?

2 posts, 0 answered
  1. Bo Chulindra
    Bo Chulindra avatar
    35 posts
    Registered:
    17 Dec 2013
    30 Jun 2014
    Link to this post

    I have an MVC widget with two properties: one for the header of the widget and one for optional text below the header.

    I'd like the properties to have default values when the widget is placed on a page but the user should be able to change or remove the properties' values as needed.

     I tried setting the property values in the controller constructor. This almost does what I need. When the widget is placed on a page, the properties' are set to the defaults. The user can also change the properties as needed. However, if the user removes a property's value (for example, in the optional property), then the property is then set to the default. I would prefer that the property have an empty value.

     Is there a property way to set a default value for an MVC widget's property? And is there a way to let a user set a property's value to an empty string even when it has a default?

  2. Bo Chulindra
    Bo Chulindra avatar
    35 posts
    Registered:
    17 Dec 2013
    30 Jun 2014
    Link to this post
    I discovered that if I set a widget's property to a whitespace (via the widget designer), then the property will not reset to the default value.
2 posts, 0 answered