PDA

View Full Version : [CLOSED] Field value not posted to server if .Name() attribute present



matrixwebtech
Oct 25, 2014, 9:06 PM
Hi,
I set up some fields with .Name() attribute.


X.NumberFieldFor(obj => obj.Discount_Amount)
.Name("m")


X.NumberFieldFor(obj => obj.Tax_Amount)
.Name("m")

I use name for some javascript function


var fields = Ext.select('*[name=' m ']');

but the problem is ,if .Name attribute present in field then when I submit its value not posted to server otherwise if remove this then I get the value.

Daniil
Oct 27, 2014, 7:06 AM
Hi @matrixwebtech,


when I submit its value not posted to server

Please clarify how you determine that.

matrixwebtech
Oct 27, 2014, 7:34 AM
Hi Daniil ,Good morning,please see my example

View


@model e.Controllers.Fieldvaluenotpostedtoserver

@{

var X = Html.X();

}
@X.ResourceManager()

@(X.FormPanel().ID("f")
.Items(
X.NumberFieldFor(obj=>obj.i)
.Name("m")
.ID("nf")
)
.Buttons(
Html.X().Button()
.ID("btnEdit")
.Text("Click")

.DirectEvents(de =>
{
de.Click.FormID = "f";
de.Click.Action = "click";

})
)
)

Controller


public class FieldvaluenotpostedtoserverController : Controller
{
//
// GET: /Fieldvaluenotpostedtoserver/

public ActionResult Index()
{
return View();
}

public void click(Fieldvaluenotpostedtoserver _obj)
{

}

}

public class Fieldvaluenotpostedtoserver
{
public int i { get; set; }
}

Steps to reproduce
1. run this code and put any numeric value to field and click on button.
If you debug the code then you will get "0" in "_obj.i"
2.comment .Name("m") from field and do same and you get appropriate value in "_obj.i"

Daniil
Oct 27, 2014, 9:24 AM
The NumberField's value is still in POST, but with the "m" key according to the Name property's value.

"m" doesn't match any property of the Fieldvaluenotpostedtoserver class.

For example, is there any reason why this POST

SomeProperty: "some value"
should go to this class?

class SomeClass
{
public string AnotherProperty { ... }
}

"SomeProperty" doesn't match "AnotherProperty". The same happens with your test case. "i" doesn't match "m".

matrixwebtech
Oct 27, 2014, 9:36 AM
Thanks danill ,I understand ,but as per my first post http://forums.ext.net/showthread.php?45621-Field-value-not-posted-to-server-if-Name%28%29-attribute-present&p=206831&viewfull=1#post206831 ,I have some fields bind with different viewmodel object.I assign same name attribute for some calculation with javascript


var fields = Ext.select('*[name=' m ']');

with above code I get all fields and loop through .can you please suggest me any another approach to solve both condition.

This is just come to in my mind.if I use


.InputAttrTpl(X.XTemplate().Html("Name=m"))

then is it help full?

Daniil
Oct 27, 2014, 6:25 PM
I assign same name attribute for some calculation with javascript

var fields = Ext.select('*[name=' m ']');

You could use another attribute. The Name one is used as keys in POST. I guess you can use any other custom attribute.

matrixwebtech
Oct 27, 2014, 6:36 PM
Thanks,you can close this thread now.
but I not understand why you make this thread Sticky:?

Daniil
Oct 27, 2014, 6:48 PM
I have no idea how that happened:)

No Sticky now.