Bug Report T251274
Visible to All Users

TokenBox - Model binding does not work correctly after upgrading the project to version 15.1

created 10 years ago (modified 10 years ago)

Model type a comma-separated values with string bind token I have the right shows. However, the only value comes when I submit the form control. I found a solution, but to do that I need to replace the entire project. Please show me the way to examine the sample solution.

P.S. This event appeared when I update to version 15.1. The same code works in 14.2.7.

Comments (1)

    Hello,

    Thank you for contacting us. I see the problem. I will forward this issue to our R&D team. Our developers will continue working on this problem, and we will keep you informed of any progress.

    Answers approved by DevExpress Support

    created 10 years ago (modified 10 years ago)

    We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

    Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

    Additional information:

    A breaking change (BC3012) to the model binding approach has been introduced for the TokenBox editor during the implementation of the T196010 suggestion.

    Previously (prior to 15.1), the TokenBox transferred its value (which can contain single or multiple tokens) between server and client as a simple string (such as "val1,val2,val4"). This caused an issue when it was required to bind the TokenBox value (with multiple tokens) to a model field of the IEnumerable-supported type. The TokenBox could not bind to such complex structures automatically, and it was required to parse the TokenBox value (a string) in the Controller to obtain individual tokens and to correctly put them to the model.

    Now (from 15.1), the TokenBox value (tokens) is transferred using a JSON structure (such as {"val1", "val2", "val4"}). As a result, the TokenBox can be automatically bound to model fields of the IEnumerable type. However, this improvement breaks the old approach of using a non-enumerable (string) value as an Action method's parameter to transfer tokens and obtain them in the Controller by parsing the received string value. This approach will not work because only the first value of the JSON structure is now returned as a string if a non-enumerable value is used as an Action method's parameter.

    To work around this issue and allow you to continue using the previous approach, we have introduced the TokenBoxExtension.GetSelectedValues static method. It can be used in the Controller to obtain the TokenBox tokens.

    Model:

    C#
    public class ModelType { public int ID { get; set; } public string Tokens { get; set; } //old declaration }

    Controller:

    C#
    public ActionResult ControllerMethod(ModelType model) { model.Tokens = string.Join(",", TokenBoxExtension.GetSelectedValues<string>("myTokenBox")); ... return View(); }

    However, it appears that the best (and recommended) solution would be redesigning a Model, so that it contains the IEnumerable-supported field to which to bind the TokenBox.

    Model:

    C#
    public class ModelType { public int ID { get; set; } public List<string> Tokens { get; set; } //redesigned declaration }

    Controller:

    C#
    public ActionResult ControllerMethod(ModelType model){ //no string-to-list conversion is required here in 15.1 ... return View(); }

    See Also:
    T196024: DevexpressEditorsBinder - Support binding multiple values selected in MVC editor extensions to a Model's collection-type property

      Comments (2)
      Anthony (DevExpress Support) 10 years ago

        [DevExpress Support team: this comment was created from a creator's answer]
        Working correctly Model of IEnumerable type when I submit the form control. But it does not work when I want to bind data Model of IEnumerable type.

        Example Url : http://localhost:2799/V1514NotWork

        I found viewdata used as a solution, but that it should be used in this way

        Model:

        C#
        public class V1514NotWorkViewModel { public List<string> Data { get; set; } }

        Controller:public ActionResult Index()
        { V1514NotWorkViewModel defaultViewModel = new V1514NotWorkViewModel(); defaultViewModel.Data = new List<string>(); defaultViewModel.Data.Add("Tag1"); defaultViewModel.Data.Add("Tag2"); defaultViewModel.Data.Add("Tag3"); defaultViewModel.Data.Add("Tag4"); defaultViewModel.Data.Add("Tag5"); ViewData["DataForTokenBox"] = string.Join(",", defaultViewModel); return View(defaultViewModel); }

        View:

        C#
        @model DXWebApplicationTokenProblem.Models.V1514NotWorkViewModel @{ ViewBag.Title = "Index"; } <h2>Devexpress V.15.1 NotWork</h2> @using (Html.BeginForm("Submit", "V1514NotWork")) { @Html.DevExpress().TokenBoxFor(m => m.Data, settings => { settings.Properties.AllowCustomTokens = true; }).Bind(ViewData["DataForTokenBox"]).GetHtml() <br /> <input type="submit" value="Send"/> }
        Anthony (DevExpress Support) 10 years ago

          Hello,

          To process your recent post more efficiently, I created a separate ticket on your behalf: T261047: TokenBox - The tokenbox cannot be bound to IEnumerable. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.