I have a Grid with foreign key column 'Products' with custom editor template. There is a separate button 'Add new Product; which opens up a modal to add new product . After adding new product when I try to create a new record in the Grid and select the newly added product, it shows up as blank in the Grid. When I refresh the page it shows up then. What I am missing?
Foreign key in grid:
columns.ForeignKey(c => c.ID, (System.Collections.IEnumerable)ViewData["products"], "ID", "ProductName").Title("Product")..EditorTemplateName("RemoteForeignKeyProducts).
'RemoteForeignKeyProducts' is the custom editor template for products:
@model object
@(Html.Kendo().DropDownListFor(m => m)
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetProducts", "Home").Type(HttpVerbs.Post);
}).ServerFiltering(false);
})
.DataValueField("ID")
.DataTextField("ProductName")
)
GetProducts() is a function in controller
public ActionResult GetProducts()
{
using ( var db = new Entities())
{
var objects = db.Products.Select(p => new { p.ID, p.ProductName}).ToList();
return Json(objects);
}
}