AntonCharov
Mar 17, 2020, 12:53 PM
This is demo controller. I use EF 6. When i try to change field it's shown 500 status code. What i'm doing wrong?
public ActionResult ShowAllRequests()
{
IEnumerable<Request> list = new List<Request>(new Request[] {
new Request() { RequestID = 1, IsDone = true, RequestName = "r1",
Brigade = new Brigade() { BrigadeID = 1, BrigadeName = "b1"} },
new Request() { RequestID = 2, IsDone = true, RequestName = "r2",
Brigade = new Brigade() { BrigadeID = 2, BrigadeName = "b2"}}
});
return PartialView("RequestsGrid", list);
}
public ActionResult GetBrigades()
{
IEnumerable<BrigadeComboBox> list =
new List<BrigadeComboBox>(new BrigadeComboBox[] {
new BrigadeComboBox { BrigadeName = "b1", Brigade = new Brigade() { BrigadeID = 1, BrigadeName = "b1"} },
new BrigadeComboBox { BrigadeName = "b2", Brigade = new Brigade() { BrigadeID = 2, BrigadeName = "b2"} }
});
return this.Store(list);
}
public ActionResult RequestHandleChanges(StoreDataHandler handler)
{
List<Request> requests = handler.ObjectData<Request>();
if (handler.Action == StoreAction.Update)
{
}
return handler.Action == StoreAction.Update ? (ActionResult)this.Store(requests) : (ActionResult)this.Content(""); ;
}
Models
public class Request
{
[Field(FieldType = typeof(Ext.Net.Hidden))]
public int RequestID { get; set; }
[Display(Name = "Ðазвание")]
public string RequestName { get; set; }
[Display(Name = "Комментарий")]
public string Comment { get; set; }
[Display(Name = "Дата начала")]
public DateTime Start { get; set; }
[Display(Name = "Дата окончаниÑ")]
public DateTime End { get; set; }
[Display(Name = "Закрыто")]
public bool IsDone { get; set; }
[UIHint("Brigade")]
public virtual Brigade Brigade { get; set; }
}
public class Brigade
{
[Field(FieldType = typeof(Ext.Net.Hidden), Ignore = true)]
[ModelField(IDProperty = true, UseNull = true)]
public int BrigadeID { get; set; }
[Required]
[PresenceValidator]
[Display(Name = "Ðазвание")]
public string BrigadeName { get; set; }
public virtual ICollection<Request> Requests { get; set; }
}
public class BrigadeComboBox
{
public string BrigadeName;
public Brigade Brigade;
}
This is my cshtml. It loads on main page by @Html.Partail("ShowAllRequests")
@model IEnumerable<GeoSystem.Models.Request>
<script>
var brigadeRenderer = function (value) {
if (!Ext.isEmpty(value)) {
return value.BrigadeName;
}
return value;
};
var onStoreException = function (proxy, response, operation) {
var error = operation.getError(),
message = Ext.isString(error) ? error : ('(' + error.status + ')' + error.statusText);
Ext.net.Notification.show({
iconCls: 'icon-exclamation',
html: message + "\n<br /><b>Proxy type:</b> " + proxy.type,
title: 'EXCEPTION',
scrollable: 'both',
hideDelay: 5000,
width: 300,
height: 200
});
};
</script>
@(Html.X().Store()
.ID("BrigadeStore")
.Model(Html.X().Model()
.Fields(
new ModelField("brigade", ModelFieldType.Object) { Mapping = "Brigade" },
new ModelField("BrigadeName", ModelFieldType.String) { Mapping = "BrigadeName" }
)
)
.Proxy(Html.X().AjaxProxy()
.Url(Url.Action("GetBrigades"))
.Reader(Html.X().JsonReader().RootProperty("data"))
)
)
@(Html.X().GridPanel()
.ID("GridPanelRequest")
.Store(Html.X().Store()
.Model(Html.X().Model()
.Fields(
new ModelField("ID", ModelFieldType.Int),
new ModelField("RequestName"),
new ModelField("Comment"),
new ModelField("Start", ModelFieldType.Date),
new ModelField("End", ModelFieldType.Date),
new ModelField("IsDone", ModelFieldType.Boolean),
new ModelField()
{
Name = "Brigade",
Type = ModelFieldType.Object
}
)
)
.AutoSync(true)
.ShowWarningOnFailure(true)
.Listeners(l =>
{
l.Exception.Fn = "onStoreException";
l.Exception.Buffer = 10;
})
.SyncUrl(Url.Action("RequestHandleChanges"))
.DataSource(Model)
)
.Icon(Icon.Table)
.Frame(true)
.Title("ЗаÑвки")
.Height(430)
.Width(700)
.StyleSpec("margin-top: 10px;")
.ColumnModel(
Html.X().Column()
.Text("Ðомер")
.DataIndex("Id"),
Html.X().Column()
.Text("Ðазвание")
.DataIndex("RequestName")
.Editor(
Html.X().TextField().AllowBlank(false)
),
Html.X().Column()
.Text("Комментарий")
.DataIndex("Comment")
.Editor(
Html.X().TextField().AllowBlank(false)
),
Html.X().DateColumn()
.Text("Ðачало")
.DataIndex("Start")
.Editor(
Html.X().DateField().AllowBlank(false)
),
Html.X().DateColumn()
.Text("Конец")
.DataIndex("End")
.Editor(
Html.X().DateField().AllowBlank(false)
),
Html.X().BooleanColumn()
.Text("Завершено")
.DataIndex("IsDone")
.Editor(
Html.X().TextField().AllowBlank(false)
),
Html.X().Column()
.Text("Бригада")
.DataIndex("Brigade")
.Width(240)
.Renderer("brigadeRenderer")
.Editor(
Html.X().ComboBox()
.QueryMode(DataLoadMode.Remote)
.TriggerAction(TriggerAction.All)
.StoreID("BrigadeStore")
.ValueField("brigade")
.DisplayField("BrigadeName")
)
)
.Plugins(
Html.X().CellEditing()
)
)
public ActionResult ShowAllRequests()
{
IEnumerable<Request> list = new List<Request>(new Request[] {
new Request() { RequestID = 1, IsDone = true, RequestName = "r1",
Brigade = new Brigade() { BrigadeID = 1, BrigadeName = "b1"} },
new Request() { RequestID = 2, IsDone = true, RequestName = "r2",
Brigade = new Brigade() { BrigadeID = 2, BrigadeName = "b2"}}
});
return PartialView("RequestsGrid", list);
}
public ActionResult GetBrigades()
{
IEnumerable<BrigadeComboBox> list =
new List<BrigadeComboBox>(new BrigadeComboBox[] {
new BrigadeComboBox { BrigadeName = "b1", Brigade = new Brigade() { BrigadeID = 1, BrigadeName = "b1"} },
new BrigadeComboBox { BrigadeName = "b2", Brigade = new Brigade() { BrigadeID = 2, BrigadeName = "b2"} }
});
return this.Store(list);
}
public ActionResult RequestHandleChanges(StoreDataHandler handler)
{
List<Request> requests = handler.ObjectData<Request>();
if (handler.Action == StoreAction.Update)
{
}
return handler.Action == StoreAction.Update ? (ActionResult)this.Store(requests) : (ActionResult)this.Content(""); ;
}
Models
public class Request
{
[Field(FieldType = typeof(Ext.Net.Hidden))]
public int RequestID { get; set; }
[Display(Name = "Ðазвание")]
public string RequestName { get; set; }
[Display(Name = "Комментарий")]
public string Comment { get; set; }
[Display(Name = "Дата начала")]
public DateTime Start { get; set; }
[Display(Name = "Дата окончаниÑ")]
public DateTime End { get; set; }
[Display(Name = "Закрыто")]
public bool IsDone { get; set; }
[UIHint("Brigade")]
public virtual Brigade Brigade { get; set; }
}
public class Brigade
{
[Field(FieldType = typeof(Ext.Net.Hidden), Ignore = true)]
[ModelField(IDProperty = true, UseNull = true)]
public int BrigadeID { get; set; }
[Required]
[PresenceValidator]
[Display(Name = "Ðазвание")]
public string BrigadeName { get; set; }
public virtual ICollection<Request> Requests { get; set; }
}
public class BrigadeComboBox
{
public string BrigadeName;
public Brigade Brigade;
}
This is my cshtml. It loads on main page by @Html.Partail("ShowAllRequests")
@model IEnumerable<GeoSystem.Models.Request>
<script>
var brigadeRenderer = function (value) {
if (!Ext.isEmpty(value)) {
return value.BrigadeName;
}
return value;
};
var onStoreException = function (proxy, response, operation) {
var error = operation.getError(),
message = Ext.isString(error) ? error : ('(' + error.status + ')' + error.statusText);
Ext.net.Notification.show({
iconCls: 'icon-exclamation',
html: message + "\n<br /><b>Proxy type:</b> " + proxy.type,
title: 'EXCEPTION',
scrollable: 'both',
hideDelay: 5000,
width: 300,
height: 200
});
};
</script>
@(Html.X().Store()
.ID("BrigadeStore")
.Model(Html.X().Model()
.Fields(
new ModelField("brigade", ModelFieldType.Object) { Mapping = "Brigade" },
new ModelField("BrigadeName", ModelFieldType.String) { Mapping = "BrigadeName" }
)
)
.Proxy(Html.X().AjaxProxy()
.Url(Url.Action("GetBrigades"))
.Reader(Html.X().JsonReader().RootProperty("data"))
)
)
@(Html.X().GridPanel()
.ID("GridPanelRequest")
.Store(Html.X().Store()
.Model(Html.X().Model()
.Fields(
new ModelField("ID", ModelFieldType.Int),
new ModelField("RequestName"),
new ModelField("Comment"),
new ModelField("Start", ModelFieldType.Date),
new ModelField("End", ModelFieldType.Date),
new ModelField("IsDone", ModelFieldType.Boolean),
new ModelField()
{
Name = "Brigade",
Type = ModelFieldType.Object
}
)
)
.AutoSync(true)
.ShowWarningOnFailure(true)
.Listeners(l =>
{
l.Exception.Fn = "onStoreException";
l.Exception.Buffer = 10;
})
.SyncUrl(Url.Action("RequestHandleChanges"))
.DataSource(Model)
)
.Icon(Icon.Table)
.Frame(true)
.Title("ЗаÑвки")
.Height(430)
.Width(700)
.StyleSpec("margin-top: 10px;")
.ColumnModel(
Html.X().Column()
.Text("Ðомер")
.DataIndex("Id"),
Html.X().Column()
.Text("Ðазвание")
.DataIndex("RequestName")
.Editor(
Html.X().TextField().AllowBlank(false)
),
Html.X().Column()
.Text("Комментарий")
.DataIndex("Comment")
.Editor(
Html.X().TextField().AllowBlank(false)
),
Html.X().DateColumn()
.Text("Ðачало")
.DataIndex("Start")
.Editor(
Html.X().DateField().AllowBlank(false)
),
Html.X().DateColumn()
.Text("Конец")
.DataIndex("End")
.Editor(
Html.X().DateField().AllowBlank(false)
),
Html.X().BooleanColumn()
.Text("Завершено")
.DataIndex("IsDone")
.Editor(
Html.X().TextField().AllowBlank(false)
),
Html.X().Column()
.Text("Бригада")
.DataIndex("Brigade")
.Width(240)
.Renderer("brigadeRenderer")
.Editor(
Html.X().ComboBox()
.QueryMode(DataLoadMode.Remote)
.TriggerAction(TriggerAction.All)
.StoreID("BrigadeStore")
.ValueField("brigade")
.DisplayField("BrigadeName")
)
)
.Plugins(
Html.X().CellEditing()
)
)