I need to auto populate three fields when a new record is added to the grid using the Plus + button on the grids edit menu. The contents of two of these fields, JobID and StackID, are passed into the controller.cs as part of the URL string.
E.g.
[HttpGet]
public ActionResult Index(string jobID, string stackID, int? testTypeID)
The testTypeID value will always be a static ‘5’ in this instance, and this is ok.
How do I insert the current jobID and stackID values into a new grid line?
I’ve added this ClientSideEvents type to the @(Html.EJ().Grid
.ClientSideEvents(eve => eve.ActionComplete("actionComplete").ActionBegin("actionBegin"))
This then calls the following JavaScript which I want to populate a new record with the three values.
function actionBegin(args) {
if ((args.requestType == "add")) {
args.data["JobID"] = this.JobID;
args.data["StackID"] = this.StackID;
args.data["TestTypeID"] = 5;
}
}
This isn’t currently working as I’m not sure how I get JobID and StackID values into the add data.
I’m using MVC with EJ1
Query#:Adding default (not user-inputted) data into a new grid line - I wanted to do was pass the ViewBag.jobID, and ViewBag.stackID data into the grid as Default values, but it didn't seem to like me doing this.
We have checked the query at our end and it is possible to pass the ViewBag.jobID and ViewBag.stackID data into the grid as Default values in the controller page and set it as default value in the grid column field to which you want to show when on perform adding and editing operation.
Index.cshtml
…………. .. . .
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Add();
col.Field("CustomerID").HeaderText("CustomerID").DefaultValue(ViewBag.stackID).Add();
col.Field("EmployeeID").HeaderText("Employee ID").DefaultValue(ViewBag.jobID).Add();
col.Field("ShipCity").HeaderText("Ship City").Add();
col.Field("ShipCountry").HeaderText("Ship Country").Add();
}))
…………. . . .
Homecontroller.cs
public ActionResult Index()
{
if (order.Count() == 0)
BindDataSource();
ViewBag.data = order;
ViewBag.stackID = "testStack"; //set the stackID value here
ViewBag.jobID = "testJob"; // set the jobID value here
return View();
} |
Using ForeingKeyfield this does not work!!