Skip to content

Replies

0
Adrian Kullick
Adrian Kullick answered on Jul 16, 2016 4:51 AM

Hello Sam. 

Thank you for your reply. 

"Also note that to submit a form not that the <input> element will have a type of submit which is missing in your sample"

I explicitly removed the submit button. I had this in my view: 

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-default" value="Save Company" />
</div>
</div>

This button would have only saved the company name and company address, but not my changes from my employee table. My goal is to save the changes from the company form and from the employee table with only one save button. Is there a way to pass the current state of the Model to my SaveData() controller method? 

So my SaveData will look something like this SaveData(Company myCompany)

and in my View I would pass the current Modelstate => UpdateUrl(Url.Action("SaveData", Model)) 

Thank you very much. 

0
Adrian Kullick
Adrian Kullick answered on Jul 15, 2016 8:06 AM

Hello Sam. Thank you for your reply. This is how the SaveData method in the controller looks like: 

[HttpPost]
public ActionResult SaveData()
{

   GridModel gridModel = new GridModel();
   List<Transaction<Employee>> transactions = gridModel.LoadTransactions<Employee>…

   (HttpContext.Request.Form["ig_transactions"]);

   // here im getting the changes of the employee table. This works fine

   //But how do I get the changes of my company? 

   foreach (Transaction<Employee> t in transactions)
   {
        //do something..
   }

   JsonResult result = new JsonResult();
   Dictionary<string, bool> response = new Dictionary<string, bool>();
   response.Add("Success", true);
   result.Data = response;
   return result;
}

I tryed putting the input element inside the curly brackets of the form, but it didnt work. 

This is how my complete view looks like:

<!– Ignite UI Required Combined CSS Files –>
<link href="http://cdn-na.infragistics.com/igniteui/2016.1/latest/css/themes/infragistics/infragistics.theme.css&quot; rel="stylesheet" type="text/css" />
<link href="http://cdn-na.infragistics.com/igniteui/2016.1/latest/css/structure/infragistics.css&quot; rel="stylesheet" type="text/css" />

<script src="http://ajax.aspnetcdn.com/ajax/modernizr/modernizr-2.8.3.js&quot; type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js&quot; type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js&quot; type="text/javascript"></script>

<!– Ignite UI Required Combined JavaScript Files –>
<script src="http://cdn-na.infragistics.com/igniteui/2016.1/latest/js/infragistics.core.js&quot; type="text/javascript"></script>
<script src="http://cdn-na.infragistics.com/igniteui/2016.1/latest/js/infragistics.lob.js&quot; type="text/javascript"></script>
<!– Used to add modal loading indicator for igGrid –>
<script src="http://www.igniteui.com/js/grid-modal-loading-inicator.js"></script&gt;

@using Infragistics.Web.Mvc
@model WebApplication1.Models.Company
@{
ViewBag.Title = "Index";
}
<h2>Edit – Company</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
<div class="form-group">
@Html.LabelFor(model => model.CompanyName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CompanyName, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Address, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Address, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>
</div>
<hr />
<hr />
<h2>Employee List</h2>
@(Html.Infragistics()
.Grid(Model.EmployeeList).ID("Grid").Width("100%").Height("150px").PrimaryKey("ID")
.AutoGenerateColumns(false).AutoGenerateLayouts(false).EnableHoverStyles(false)
.Columns(column =>
{
column.For(x => x.FirstName).HeaderText("First Name").Width("40%");
column.For(x => x.LastName).HeaderText("Last Name").Width("40%");
})
.Features(features =>
{
features.Updating().ColumnSettings(cs =>
{
}).EnableAddRow(false).EnableDeleteRow(false);
})
.UpdateUrl(Url.Action("SaveData"))
.DataBind()
.Render()
)
<input type="button" id="saveChanges" class="button-style" value="Save" />
}

<script>
var updates, loadingIndicator;

$(function () {
var grid = $("#Grid"), comboDataSource = {};
$("#saveChanges").igButton({ labelText: $("#saveChanges").val(), disabled: false });

loadingIndicator = new GridModalLoadingIndicator(grid);

$("#saveChanges").on('igbuttonclick',
function (e) {

grid.igGrid("saveChanges", function saveSuccess() {
loadingIndicator.hide();
});
loadingIndicator.show();
return false;
}
);
});

</script>