Jan 12, 2015, 9:28 PM
[CLOSED] mvc data annotation not working ?
Hi, I try to set display name and date format, error message using data annotation, but it seems the settings were ignored. Any idea?
Thanks
-szhang
This is my code example:
Thanks
-szhang
This is my code example:
@model IEnumerable<CPMExtnet.ViewModels.EmployeePlaceholder>
@section content
{
@(X.Viewport().Layout(LayoutType.Fit)
.Items (
X.GridPanel()
.ID("EmployeePlaceholderGrid")
.Title ("Your Employee Placeholders")
.Icon(Icon.Table)
.Frame(true)
.ForceFit(true)
.AutoScroll(true)
.Store(
X.StoreForModel().Control (ctl =>
{
ctl.AutoSync = true;
ctl.Proxy.Add(
new RestProxy
{
AppendAction = false,
Reader = {
new JsonReader {
Root = "data",
MessageProperty = "message"
}
},
API =
{
Read = Url.Action("ReadEmployeePlaceholders"),
Update = Url.Action("UpdateEmployeePlaceholder"),
Create = Url.Action("CreateEmployeePlaceholder")
},
Writer = {
new JsonWriter
{
AllowSingle = true
}
}
}
);
})
)
.ColumnModel(
X.ColumnFor(Model, m=> m.PEID),
X.ColumnFor (Model, m=> m.Name)
.ToBuilder<Column.Builder>()
.Editor(
X.TextField().AllowBlank(false)
),
X.ColumnFor(Model, m=> m.BasePayStartDate)
.ToBuilder<Column.Builder>()
.Editor (
X.DateField().AllowBlank(false)
)
)
.TopBar(
Html.X().Toolbar()
.Items(
Html.X().Button()
.Text("Add")
.Icon(Icon.Add)
.Handler("InsertEmployeePlaceholder (this.up('grid'));"),
)
)
.BottomBar(X.PagingToolbar())
.SelectionModel( X.RowSelectionModel().Mode(SelectionMode.Single))
.Plugins(
X.RowEditing()
.Listeners(l => {
l.CancelEdit.Handler = "if(e.record.phantom){e.store.remove(e.record);}";
})
)
this the model code:
[Model(Name = "EmployeePlaceholder")]
public class EmployeePlaceholder
{
[ModelField(IDProperty = true, UseNull = true)]
[Field(Ignore = true)]
public int? Id { get; set; }
public string PEID { get; set; }
[Required]
[StringLength(40)]
[PresenceValidation]
public string Name {get; set; }
[Required]
[PresenceValidation]
public string PositionCode {get; set;}
[Required(ErrorMessage="Start Date is required")] //instead showing error I defined here, it shows default error message
[PresenceValidation]
[DataType (DataType.Date)]
[DisplayFormat(DataFormatString = "{0:d}")] // never change the date format
[Display(Name="Start Date")] // it show column name instead
public DateTime? BasePayStartDate { get; set; }
..
Last edited by Daniil; Jan 21, 2015 at 12:51 PM.
Reason: [CLOSED]