PDA

View Full Version : [CLOSED] DataAnnotations validation not working for gridpanel



alscg
Dec 19, 2013, 2:44 PM
Hi,

When there is any property decorated with DataAnnotations any attribute (for example Required) of data source of gridpanel.
Then validation is not displayed, while this works for property which in not inside gridpanel but direct on form panel.

Please let me know what i need to do to get this working.

Thanks

Baidaly
Dec 19, 2013, 5:13 PM
Hello!

You mean CellEditing? I don't quite understand your requirements. Can you provide a sample?

alscg
Dec 20, 2013, 11:00 AM

Baidaly
Dec 20, 2013, 7:55 PM
Sorry, it's still not clear.

When you use TextFieldFor it should apply validation from the Model but when you use TextField or ComboBox it cannot know anything about the attributes in your Model. So you need to set them AllowBlank to false manually.

If you want to bind list values using MVC DefaultModel binder you should follow special naming syntax. Please, read the following: http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/

If it's still not clear please provide a full sample to reproduce.

alscg
Dec 23, 2013, 5:21 AM
Sorry, it's still not clear.

When you use TextFieldFor it should apply validation from the Model but when you use TextField or ComboBox it cannot know anything about the attributes in your Model. So you need to set them AllowBlank to false manually.

If you want to bind list values using MVC DefaultModel binder you should follow special naming syntax. Please, read the following: http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/

If it's still not clear please provide a full sample to reproduce.


I am clear what you are trying to say, according to your approach if i follow special naming syntax to get my validation work.
Then question would be is that possible in given scenario please see my View code and code to follow special naming syntax in given example(http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/).



<%@ Page Inherits="ViewPage<IList<Book>>" %>

<% for (int i = 0; i < 3; i++) { %>

<%: Html.TextBoxFor(m => m[i].Title) %>
<%: Html.TextBoxFor(m => m[i].Author) %>
<%: Html.TextBoxFor(m => m[i].DatePublished) %>

<% } %>


for example -


Html.X().ComponentColumn()
.Editor(true)
.DataIndex("DepartmentName")
.Text("Department Name")
.Component(Html.X().TextField().Name(Departments[0].DepartmentName))


Please see [Departments[0].DepartmentName] in above code sample how can i achieve this in grid panel where my 'for' loop will give indexer value here it is '0'.

Thanks

Daniil
Dec 23, 2013, 12:36 PM
Do you need an individual ComponentColumn for each Departments[0], Departments[1], Departments[2], etc.?

Please provide us with the Model, some test data and explain how you need to show the data. Regardless from the Ext.NET context. Just an explanation (and mockups if needed).

alscg
Dec 24, 2013, 7:05 AM

Daniil
Dec 25, 2013, 6:36 AM
Thank you for clarifying.

What about the following?


@{
Department depForEditor = new Department();
}


.Component(
Html.X().TextFieldFor(m => depForEditor.DepartmentName).FieldLabel("")
)

Or you can use a common TextField and its AllowBlank and BlankText properties.