Can't find equivalent of (Convert) for ModelField in MVC C#

  1. #1

    Can't find equivalent of (Convert) for ModelField in MVC C#

    Hi Community!
    The following code block is creating store of a 100% stacked-bar chart in Ext Web Form.
    <Store>
                            <ext:Store runat="server" Data="<%# Data %>" AutoDataBind="true">                           
                                <Model>
                                    <ext:Model runat="server">
                                        <Fields>
                                            <ext:ModelField Name="Month" />
                                            <ext:ModelField Name="Data1" />
                                            <ext:ModelField Name="Data2" />
                                            <ext:ModelField Name="Data3" />
                                            <ext:ModelField Name="Data4" />
                                            <ext:ModelField Name="Other">
                                                <Convert Fn="convert" />
                                            </ext:ModelField>
                                        </Fields>
                                    </ext:Model>
                                </Model>
                            </ext:Store>
                        </Store>
    I want to change the current code to C# MVC, I created the store and the rest of the parts but I can't find the equivalent of this part
    <Convert Fn="convert" />
    in C# MVC. can anybody help me, please?
    Last edited by nasim; Jan 09, 2016 at 11:56 AM.
  2. #2
    Hello @nasim!

    We have three examples in our MVC Examples explorer using it, give them a look:

    - Basic FormPanel
    - GridPanel's Data Presentation: Data Prepare
    - GridPanel's Data Presentation: Field Converter

    I'm not sure which way you are trying to write in your razor syntax, so I leave the examples showcasing the two different approaches you can use to set that config.

    Generally speaking:
    1. when you add an item as a Html.X().ItemNameHere(), to add a JFunction config (a config that can accept Fn or Handler properties, for example), you can do it by appending a .ConfigName(what => what.Fn = "myFn") or when you need more than one props set:
    Html.X().ItemNameHere()
        .ConfigName(what =>
        {
            what.Fn = "myFn";
            what.Handler = "console.log('handler')"
        }
    2. when you add via instantiating (using new keyword) you always get the error 'the variable is read-only' when you try to bind it like:
    new MyItem()
    {
        propValue = new ConfigName()
        {
            Fn = "whatever"
        }
    }
    You have to do so via this way:
    new MyItem()
    {
        propValue =
        {
            Fn = "whatever"
        }
    }
    These are two ways to accomplish these mappings, and it can be extended to other config types (not only the ones to receive Fn and Handler). This does not mean there are only these two manners to use them, it just means these are two proper ways to express those settings using Razor syntax. Again, the examples linked in the beginning showcase both uses.

    Hope this helps!

    EDIT: These samples were extracted from Ext.NET 3.2.1 examples explorer. This may not apply to using MVC on Ext.NET 1, where MVC support was rather limited. If this does not apply, please provide the test case with what you could produce so far.
    Last edited by fabricio.murta; Jan 09, 2016 at 4:25 PM.
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hi @fabricio.murta
    Thank you so much for your suggests.
    I am using Ext .Net server-side objects, so I need C# codes instead of Razor ones.
    So I found this and it works:
    var modelField = new ModelField{ Name = "Other",Type = ModelFieldType.String };
    modelField.Convert.Fn = "";

Similar Threads

  1. [CLOSED] Adding a Convert handler to a ModelField created dynamically
    By tnwheeler in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 26, 2014, 7:37 PM
  2. [CLOSED] here how to get value of modelfield in editor?
    By hdsoso in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 02, 2014, 7:23 AM
  3. [CLOSED] how to get modelfield from RowSelectionModel?
    By hdsoso in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 10, 2014, 6:08 AM
  4. How to get ModelField Value in ComboBox
    By coder in forum 2.x Help
    Replies: 1
    Last Post: Nov 24, 2013, 2:51 AM
  5. Replies: 0
    Last Post: Dec 01, 2011, 6:43 AM

Tags for this Thread

Posting Permissions