PDA

View Full Version : [CLOSED] problem with DisplayFieldFor model binding



matrixwebtech
Jul 27, 2014, 9:17 PM
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.

Vladimir
Jul 28, 2014, 11:45 AM
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

matrixwebtech
Aug 09, 2014, 6:18 AM
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; }
}

Daniil
Aug 10, 2014, 2:32 PM
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.