This question is locked. New answers and comments are not allowed.
Hi, everybody I'm new using this controls and I can't find the way to make a foreignkey column to show a dropdown on editmode, this is my controller.
namespace MvcApplication3.Controllers
{
public class HomeController : Controller
{
public PortalRepository entities = new PortalRepository();
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
ViewData["modulos"] = entities.GetAllModules().ToList();
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
[GridAction]
public ActionResult GridUpdate( int rolID)
{
var rol = new RolesModulo
{
RolID = rolID
};
if (TryUpdateModel(rol))
{
entities.UpdateRol(rol);
//return RedirectToAction("Index", this.GridRouteValues());
}
//return View("Index", entities.GetAllRoles());
return View(new GridModel(entities.GetAllRoles()));
}
[AcceptVerbs(HttpVerbs.Post)]
[GridAction]
public ActionResult GridInsert()
{
var rol = new RolesModulo();
if (TryUpdateModel(rol))
{
entities.AddRol(rol);
//return RedirectToAction("Index", this.GridRouteValues());
}
//return View("Index", this.GridRouteValues());
return View(new GridModel(entities.GetAllRoles()));
}
[GridAction]
public ActionResult GridSelect()
{
return View(new GridModel(entities.GetAllRoles()));
}
public ActionResult About()
{
return View();
}
}
}
And this is the view
@using Telerik.Web.Mvc.UI;
@using MvcApplication3.Models;
@using System.Collections;
@{
ViewBag.Title = "Home Page";
}
<h2>@ViewBag.Message</h2>
<p>
To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc<;/a>.
</p>
@(
Html.Telerik().Grid<RolesModulo>("roles")
.Name("grid")
.DataKeys(k=> k.Add(o=> o.RolID))
.ToolBar(c=>c.Insert().ButtonType(GridButtonType.Image))
.Columns(c =>
{
c.Bound(o => o.RolID).Hidden();
c.Bound(o => o.Activo);
c.Bound(o => o.Nombre);
c.Bound(o => o.Descripcion);
c.ForeignKey(o => o.ModuloID, (IEnumerable)ViewData["modulos"], "ModuloID", "Nombre").Title("Módulo");
c.Command(s =>
{
s.Edit();
});
})
.DataBinding( b=> b.Ajax()
.Select("GridSelect","Home")
.Insert("GridInsert", "Home")
.Update("GridUpdate", "Home")
)
.Pageable()
.Sortable()
.Filterable()
.Groupable()
)
I have tried to make it work with Ajax and Server Binding. I can't figure why shows the correct info on browse mode, but won't show the dropdown.
Any help would be deeply appreciated.