Im trying to create a master / detail create page in mvc 5
at the top I have normal text input fields
at the buttom I have a grid
when I post back the data I entered in the grid is not there
the model look like this
public Bestiller bestilleren { get; set; }public IQueryable<Kontaktperson> kontaktpersoner { get; set; }
and the grid :
@(Html.Infragistics().Grid(Model.kontaktpersoner).PrimaryKey("ID").ID("grdKontaktpersoner").ShowHeader(true).Columns(column =>{column.For(m => m.ID).Hidden(true);column.For(m => m.Navn).HeaderText("Navn").Width("200px");column.For(m => m.E_Mail).HeaderText("Email").Width("200px");column.For(m => m.Tlfnr).HeaderText("Telefonnr.").Width("80px");column.For(m => m.RefNr).HeaderText("Ref. Nr.").Width("100px");}).Features(feature =>{feature.Updating().ColumnSettings(cs =>{cs.ColumnSetting().ColumnKey("ID").ReadOnly(true);cs.ColumnSetting().ColumnKey("Navn").EditorType(ColumnEditorType.Text).Required(true).TextEditorOptions(o => o.ValidatorOptions(vo => vo.MaxLength(50)));cs.ColumnSetting().ColumnKey("E_Mail").EditorType(ColumnEditorType.Text).TextEditorOptions(o => .ValidatorOptions(vo => vo.MaxLength(60)));cs.ColumnSetting().ColumnKey("Tlfnr").EditorType(ColumnEditorType.Text).TextEditorOptions(o => o.ValidatorOptionsvo => vo.MaxLength(20)));cs.ColumnSetting().ColumnKey("RefNr").EditorType(ColumnEditorType.Text).TextEditorOptions(o => o.ValidatorOptionsvo => vo.MaxLength(30)));}).CancelLabel("Afbryd").AddRowLabel("Tilføj kontaktperson").DeleteRowTooltip("Slet kontaktperson").DoneLabel("Gem").EditMode(GridEditMode.Row).EnableDeleteRow(true);}).AutoGenerateColumns(false).AutoAdjustHeight(true).AutoCommit(true).Width("100%").DataSource(Model.kontaktpersoner).DataBind().Render())
I use 2014.1 sr 2249
Hi Christian,
I am still following this thread. Let me know if you need additional information. Thanks!
There are a couple of things that I notice. The first is in your view where you set your UpdateUrl, I see you call KontaktPersonGem, but you don't seem to tell the updateurl where to find KontaktPersonGem. The UpdateUrl should look something like this:
.UpdateUrl(Url.Action("KontaktPersonGem", "Home"))
Also I see you are calling AutoCommit(true) but you need to also call SaveChanges. So, something like this:
<script type="text/javascript">
function saveChanges() {
$("#grid1").igGrid("saveChanges");
}
</script>
<input type="button" id="saveChanges" value="Save Changes" onclick="saveChanges()" />
Finally, I don't have access to what you're doing in KontaktPersonGem, but if all is working there fine, the updates should successfully save.
Going with my example provided above, this is what I am doing in my UpdateGrid ActionResult that I pass into my UpdateUrl:
public ActionResult UpdateGrid(string ig_transactions)
{
//postData = HttpContext.Request.Form["ig_transactions"];
//ArrayList data = (ArrayList)Procurios.Public.JSON.JsonDecode(ig_transactions);
GridModel m = new GridModel();
List<Transaction<Wine>> transactions = m.LoadTransactions<Wine>(HttpContext.Request.Form["ig_transactions"]);
ViewData["GenerateCompactJSONResponse"] = false;
foreach (Transaction<Wine> t in transactions)
switch (t.type)
case "row":
wl.UpdateWine(t.row);
break;
case "newrow":
wl.AddWine(t.row);
case "deleterow":
wl.DeleteWine(Convert.ToInt32(t.rowId));
};
JsonResult result = new JsonResult();
Dictionary<string, bool> response = new Dictionary<string, bool>();
response.Add("Success", true);
result.Data = response;
return result;
Please let me know if you need additional assistance.
I change the grid to this
@{
var data = Model.Kontaktperson.AsQueryable();
@(Html.Infragistics().Grid<intranet.mvc5.Models.Kontaktperson>(data)
.PrimaryKey("ID")
.ID("grdKontaktpersoner")
.ShowHeader(true)
.Columns(column =>
column.For(m => m.ID).Hidden(true);
column.For(m => m.Navn).HeaderText("Navn").Width("200px");
column.For(m => m.E_Mail).HeaderText("Email").Width("200px");
column.For(m => m.Tlfnr).HeaderText("Telefonnr.").Width("80px");
column.For(m => m.RefNr).HeaderText("Ref. Nr.").Width("100px");
})
.Features(feature =>
feature.Updating().ColumnSettings(cs =>
cs.ColumnSetting().ColumnKey("ID").ReadOnly(true);
cs.ColumnSetting().ColumnKey("Navn").EditorType(ColumnEditorType.Text).Required(true).TextEditorOptions(o => o.ValidatorOptions(vo => vo.MaxLength(50)));
cs.ColumnSetting().ColumnKey("E_Mail").EditorType(ColumnEditorType.Text).TextEditorOptions(o => o.ValidatorOptions(vo => vo.MaxLength(60)));
cs.ColumnSetting().ColumnKey("Tlfnr").EditorType(ColumnEditorType.Text).TextEditorOptions(o => o.ValidatorOptions(vo => vo.MaxLength(20)));
cs.ColumnSetting().ColumnKey("RefNr").EditorType(ColumnEditorType.Text).TextEditorOptions(o => o.ValidatorOptions(vo => vo.MaxLength(30)));
.CancelLabel("Afbryd")
.AddRowLabel("Tilføj kontaktperson")
.DeleteRowTooltip("Slet kontaktperson")
.DoneLabel("Gem")
.EditMode(GridEditMode.Row)
.EnableAddRow(true)
.EnableDeleteRow(true);
.AutoGenerateColumns(false)
.AutoAdjustHeight(true)
.AutoCommit(true)
.Width("100%")
.DataSource(data)
.UpdateUrl(Url.Action("KontaktPersonGem"))
.DataBind()
.Render()
)
model intranet.mvc5.Models.Bestiller
KontaktPersonGem never get called
Thank you for your sample. I believe all you need to do is set Bestiller_ID to be nullable. You can do this by using the nullable modifier when setting the property in your model.
Once you allow Bestiller_ID to accept a null value it should be possible to then update the data source.
I have attached a sample