This question is locked. New answers and comments are not allowed.
Hello,
I currently set up a Grid with GridEditMode.InLine to edit a child object which belongs to exactly one of a set of parent objects. I am using MVC 3 and Razor as view engine. I tried to replicate the approach from the respective demo application.
I am using the Visual Studio Default folder structure, i.e. my view resides in Views/childObject.
My controller populates the View Data with the list of id and name named "clients".
I have annotated my model to point at an editor template.
I have set up the following Editor template ClientMarketingAuthHolder.cshtml:
For display, this works just fine. However, as soon as I edit a column in my view, the display changes from the parent name to the parent id. I have tried placing my Editor template in various locations:
in ~/Views/MarketingAuthHolder/EditorTemplates
in ~/Views/MarketingAuthHolder
in ~/Views/Shared/EditorTemplates
None of the above work. What am I missing here?
Kind Regards
Stephan
I currently set up a Grid with GridEditMode.InLine to edit a child object which belongs to exactly one of a set of parent objects. I am using MVC 3 and Razor as view engine. I tried to replicate the approach from the respective demo application.
I am using the Visual Studio Default folder structure, i.e. my view resides in Views/childObject.
...
columns.ForeignKey(c => c.ClientId, (IEnumerable)ViewData["clients"], "Id", "Name").Title("Client");
...My controller populates the View Data with the list of id and name named "clients".
[OutputCache(Duration = 0)][CultureAwareAction]public ActionResult Index(){ PopulateClients(); var repository = new MarketingAuthHolderRepository(); return View(MarketingAuthHolderModel.GetAllModels(repository.GetAll()));}[GridAction][CultureAwareAction]public ActionResult SelectAjaxEditing(){ PopulateClients(); var repository = new MarketingAuthHolderRepository(); return View(new GridModel(MarketingAuthHolderModel.GetAllModels(repository.GetAll())));}private void PopulateClients(){ IRepository<Client> repository = new ClientRepository(); ViewData["clients"] = repository.GetAll() .Select(e => new { Id = e.Id, Name = e.Name }) .OrderBy(e => e.Name);}[AcceptVerbs(HttpVerbs.Post)][GridAction][CultureAwareAction]public ActionResult SaveAjaxEditing(int id){ var repository = new MarketingAuthHolderRepository(); var entity = repository.GetById(id); var model = new MarketingAuthHolderModel(entity); IRepository<Client> clientRepository = new ClientRepository(); model.Client = clientRepository.GetAll() .Where(e => e.Id == model.ClientId) .Select(e => e.Name) .SingleOrDefault(); if (TryUpdateModel(model, null, null, new[] { "Client" })) { model.UpdatedOn = DateTime.Now; model.UpdatedBy = User.Identity.Name; repository.Update(model.ToEntity()); } return View(new GridModel(MarketingAuthHolderModel.GetAllModels(repository.GetAll())));}I have annotated my model to point at an editor template.
[Key]public int Id { get; set; }[Required][Display(Name = "Name")]public string Name { get; set; }[UIHint("ClientMarketingAuthHolder"), Required]public string Client { get; set; }public int? ClientId { get; set; }I have set up the following Editor template ClientMarketingAuthHolder.cshtml:
@using System.Collections@using Telerik.Web.Mvc.UI@(Html.Telerik().DropDownList() .Name("Client") .BindTo(new SelectList((IEnumerable)ViewData["clients"], "Id", "Name")))For display, this works just fine. However, as soon as I edit a column in my view, the display changes from the parent name to the parent id. I have tried placing my Editor template in various locations:
in ~/Views/MarketingAuthHolder/EditorTemplates
in ~/Views/MarketingAuthHolder
in ~/Views/Shared/EditorTemplates
None of the above work. What am I missing here?
Kind Regards
Stephan