AntonCharov
Mar 13, 2020, 12:24 PM
I have two entities - Request and Brigade. Each request belongs to one brigade. I found an example https://mvc.ext.net/#/Models/FormPanelFor/
Here is my code
Request.cshtml - It's loads on main page by @Html.partial
@model GeoSystem.Db.ViewModel.FormPanelRequest
@(Html.X().FormPanelFor(m => m.request)
.ID("RequestPanel")
.X(10).Y(10)
.BodyPadding(5)
.DefaultAnchor("100%")
.Width(300)
.Buttons(Html.X().Button()
.Text("Сохранить")
.DirectClickUrl(Url.Action("SubmitRequest"))
)
)
In Views/Shared/EditorTemplates i add Brigade.cshtml
@using GeoSystem.Db.ViewModel;
@model FormPanelRequest
@(
Html.X()
.ComboBoxFor(m => m.request.BrigadeID)
.Items(FormPanelRequest.getBrigades().Select(d => new ListItem(d.Name, d.BrigadeID)))
.FieldLabel("Brigade")
.SimpleSubmit(true)
.Listeners(l => {
l.Select.Handler = "this.next().setValue(this.getRawValue());";
})
)
FormPanelrequest.cs
public class FormPanelRequest
{
public Request request { get; set; }
private static BrigadeRepository repository = new BrigadeRepository();
public static List<Brigade> getBrigades() {
return repository.GetAll();
}
}
And i got an exeption
System.InvalidOperationException: "The context cannot be used while the model is being created.
This exception may be thrown if the context is used inside the OnModelCreating method or if the same
context instance is accessed by multiple threads concurrently.
Note that instance members of DbContext and related classes are not guaranteed to be thread safe
How to use Entity Framework and Ext.Net?
Here is my code
Request.cshtml - It's loads on main page by @Html.partial
@model GeoSystem.Db.ViewModel.FormPanelRequest
@(Html.X().FormPanelFor(m => m.request)
.ID("RequestPanel")
.X(10).Y(10)
.BodyPadding(5)
.DefaultAnchor("100%")
.Width(300)
.Buttons(Html.X().Button()
.Text("Сохранить")
.DirectClickUrl(Url.Action("SubmitRequest"))
)
)
In Views/Shared/EditorTemplates i add Brigade.cshtml
@using GeoSystem.Db.ViewModel;
@model FormPanelRequest
@(
Html.X()
.ComboBoxFor(m => m.request.BrigadeID)
.Items(FormPanelRequest.getBrigades().Select(d => new ListItem(d.Name, d.BrigadeID)))
.FieldLabel("Brigade")
.SimpleSubmit(true)
.Listeners(l => {
l.Select.Handler = "this.next().setValue(this.getRawValue());";
})
)
FormPanelrequest.cs
public class FormPanelRequest
{
public Request request { get; set; }
private static BrigadeRepository repository = new BrigadeRepository();
public static List<Brigade> getBrigades() {
return repository.GetAll();
}
}
And i got an exeption
System.InvalidOperationException: "The context cannot be used while the model is being created.
This exception may be thrown if the context is used inside the OnModelCreating method or if the same
context instance is accessed by multiple threads concurrently.
Note that instance members of DbContext and related classes are not guaranteed to be thread safe
How to use Entity Framework and Ext.Net?