PDA

View Full Version : Trouble in ExtJs form submission to ASP.Net MVC



olakara
16 Jan 2011, 11:28 PM
Hi all,

I am trying to submit an ExtJS form to a MVC action. I am able to get data for all the fields except for checkboxes. I would like to know how to get this data. Currently, I always receive "false" even if the checkbox is check in the form.
There is my Code:

Ext JS form:

items:[{
fieldLabel:'Specification Code',
name:'spec_id',
id: 'spec_id',
required: true
},{
fieldLabel:'Description (English)',
name:'description_en',
id: 'description_en',
required: true
},{
fieldLabel:'Description (Arabic)',
name:'description_ar',
id: 'description_ar',
required: true
},{
fieldLabel:'Description (French)',
name:'description_fr',
id: 'description_fr',
required: true
},{
xtype: 'checkbox',
fieldLabel: 'Publish',
name: 'to_publish',
id: 'to_publish',
required: true
}]
On the server side, I have a Model class as:

public class SpecificationsVO : IValueObject
{
public string spec_id { set; get;}
public string description_en { set; get; }
public string description_ar { set; get; }
public string description_fr { set; get; }
public bool to_publish { set; get; }
.
.
}

In the controller my action is:

[HttpPost]
public ActionResult Create(SpecificationsVO form)
{
// Use the form object and process it...

}

When I view the values of the form, I always get the to_publish variable as false? Why is it not mapped while all other values are mapped properly? How do I map boolean variables?

I also checked, the form data being sent from the browser.. and the to_publish data is a string and not a boolean value..
http://i51.tinypic.com/x1iwax.png

Can anybody point out my mistake? How can this be corrected?

Thanks in advance,
Abdel Olakara

olakara
16 Jan 2011, 11:37 PM
Well,

After a second thought and a look at API documentation. I have found the cause!!! Here is the modified code:


xtype: 'checkbox',
fieldLabel: 'Publish',
inputValue: 'true',
name: 'to_publish',
id: 'to_publish',
required: true

Adding the inputValue fixed all the trouble I was having :) ..

dan_b
17 Jan 2011, 2:58 AM
Adding the inputValue fixed all the trouble I was having :) ..

This got me when I jumped from ASP.Net Webforms to MVC - HTML Checkboxes don't post true or false in a form submit, they either post true when checked, or not at all.