[CLOSED] problem with DisplayFieldFor model binding

  1. #1

    [CLOSED] problem with DisplayFieldFor model binding

    I take a displayfield like bellow

    X.DisplayFieldFor(obj => obj.TotalRequisitionValue).HideLabel(true)
    I am not get the object value from Controller action.

    But if i take a textfield like
    X.TextFieldFor(obj => obj.TotalRequisitionValue).HideLabel(true).Border(false).Width(121).ReadOnly(true)
    I am getting the object value from Controller action.

    what is the problem?please explain.
    Last edited by Daniil; Aug 15, 2014 at 9:50 AM. Reason: [CLOSED]
  2. #2
    Hi

    I cannot reproduce it, i tried DisplayFieldFor in this example (instead NumberFieldFor(m => m.NumberValue))
    http://mvc.ext.net/#/Models/Model_Bind/

    and all works fine

    Please provide your runable test case
  3. #3
    Hi I try with bellow code.in text box put an integer value.the same value is displayed in label.after that click on button.but not get label value at code behind.

    @using Ext.Net
    @using Ext.Net.MVC
    
    
    @model modelbind
    
    @{
        Layout = null;
    }
    
    
        <script>
            var test = function () {
    
                Ext.getCmp("i").setValue(Ext.getCmp("txttest").getValue())
            }
        </script>
    
        @Html.X().ResourceManager()
    
           @(
     Html.X().FormPanel()
            .Layout(LayoutType.Form)
            .Width(350)
            .FieldDefaults(d =>
            {
                d.LabelWidth = 150;
            })
            .BodyPadding(10)
            .Frame(true)
            .Items(
                        Html.X().TextField().ID("txttest").Listeners(l => { l.Change.Fn = "test"; }),
                Html.X().DisplayFieldFor(m => m.i)
    
            )
            .Buttons(
                                Html.X().Button()
                                .Text("Save")
                                .ID("btnSave")
    
                                .DirectEvents(de =>
                                    {
    
                                        de.Click.Action = "test";
    
    
    
    
                                    })
    
                
    
                    )
        )
    using System.Web.Mvc;
    
    namespace ERP_test.Controllers
    {
        public class modelbindController : Controller
        {
            //
            // GET: /modelbind/
    
            public ActionResult Index()
            {
                return View();
            }
            public void test(modelbind _modelbind)
            {
                
            }
    
        }
    }
    
    public class modelbind
    {
        public int i { get; set; }
    }
    Last edited by matrixwebtech; Aug 09, 2014 at 6:23 AM.
  4. #4
    Hi @matrixwebtech,

    A DisplayField is not submitted to the server automatically.

    I would try to duplicate it with a Hidden field.
    @X.DisplayFieldFor(m => m.Text, false)
    @X.HiddenFor(m => m.Text, false)
    The second "false" parameter is passed to avoid auto generation of ids. Otherwise the same id will be set up for both the fields.

Similar Threads

  1. [CLOSED] Fill controls from controller with model binding
    By matrixwebtech in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 23, 2014, 8:52 AM
  2. Form binding to the model
    By errno in forum 2.x Help
    Replies: 7
    Last Post: May 24, 2013, 5:34 AM
  3. [CLOSED] binding checkbox selection model
    By CarpFisher in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Jul 18, 2012, 7:52 AM
  4. [CLOSED] MVC, Binding model to Store
    By SymSure in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 08, 2011, 3:19 PM
  5. binding checkbox selection model
    By VipulTyagi in forum 1.x Help
    Replies: 2
    Last Post: Apr 07, 2011, 11:36 AM

Posting Permissions