when I change the GridEditMode to InForm, the Grid starts ignoring the UIHints in my ViewModel and renders standard Textboxes for my ClientTemplates instead of the Objects.
Is there a way to use an ascx partial view as EditForm? That would really solve all my problems.
You can see some sample code below.
View:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %> <% Html.Telerik().Grid<MetastasesSchemaViewModel>() .Name( "metastasesSchemaGrid" ) .DataKeys( k => k.Add( ms => ms.HealthEventId ) ) .DataBinding( d => d.Ajax().Select( "_SelectMetastasesSchemas", "Metastasis", new { area = "" } ) .Update( "_UpdateMetastasesSchema", "Metastasis", new { area = "" } ) .Delete( "_DeleteMetastasesSchema", "Metastasis", new { area = "" } ) .Insert( "_UpdateMetastasesSchema", "Metastasis", new { area = "" } ) ) .ToolBar( t => t.Insert() ) .Columns( c => { c.Bound( p => p.Date ).Format( "{0:dd.MM.yyyy}" ).Width( 120 ); c.Bound( p => p.EventConfirmations ).ClientTemplate( "<#= EventConfirmationsString #>" ); ; c.Bound( p => p.CausedMetastases ).ClientTemplate( "<#= CausedMetastasesString #>" ); c.Command( commands => { commands.Edit(); commands.Delete(); } ).Width(100); } ) .Editable(e=>e.Mode(GridEditMode.InForm)) .Scrollable() .Render(); %> ViewModel:
public class MetastasesSchemaViewModel : BaseMetastasisViewModel { public MetastasesSchemaViewModel() { } public int HealthEventId { get; set; } [DisplayName( "Datum" )] [DataType( DataType.Date )] public DateTime Date { get; set; } [DisplayName( "Neue Metastasen" )] [UIHint( "MetastasesList" )] public List<MetastasisViewModel> CausedMetastases { get; set; } public string CausedMetastasesString { get; set; } [DisplayName( "Diagnosesicherungen" )] [UIHint( "EventConfirmations" )] public List<EventConfirmationViewModel> EventConfirmations { get; set; } public string EventConfirmationsString { get; set; } } Regards,
Timo
12 Answers, 1 is accepted
As you know our grid uses DisplayForModel to display properties from the bound object, but unfortunately ASP.NET MVC 2 can't handle with complex object like Employee(in this situation). Because of that, we add TypeConverter to fix this problem. For more information read this blog post here.
For your convenience I have attached my test project.
If you want template for EditForm you have to add EditingTemplate for your object(for example EditableOrder) and you have to define UIHint for the object.
Kind regards,
Hristo Germanov
the Telerik team
Hello,
Thank you, I managed to use an SomeObject.ascx File as EditorTemplate for my Grid-bound Object even with automatically Displaying all complex-property Lists by creating a “SomeChildObjectList : List<SomeChildObject>” Class and creating the TypeConverter for that class.
Now a ran into the following Problem:
If I put my Form outside the Grid everything renders perfectly, my TypeConverters convert every complex property back into models so the Save Function in my Controller only says:
[AcceptVerbs…] // if Telerik: [GridAction] public ActionResult _SaveSomeObject( SomeObject model) { if(ModelState.IsValid) { // SomeCodeHere } }
Now I put my Form in the Grid:
a) Every CheckboxList does not convert into an Array of values of all checked Boxes (like when I use standard mvc forms), instead my TypeConverter receives one string containing “false” (very much useless), the Names of the Checkboxes correctly correspond to the Name of my complex Property.
b) If the values of these checkboxes are not simple int32 (not possible in some cases) once the EditForm is displayed every value is set to “[object] [Object]” or “”, I assume by some JavaScript because the Controller delivers the intended values.
c) In Some cases I need to change the value of a DropDownList using JavaScript upon displaying the Form. That works perfectly, but after I checked the correct value using alert or console.log some (it needs to be) JavaScript changes it back…
So my Problems at the moment are basically:
- Displaying a CheckboxList that corresponds to a List of ChildObjects in my Model, which contains a dynamic list of Options to add or remove these ChildObjects (which are complex themselves)
- Understanding what Telerik does to the values of my Html controls, probably using JavaScript
- Understanding why my Checkboxes do not return their values to the Controller, once displaying inside the GridEditForm
Regards,
Timo
Unfortunately we are not sure what has gone wrong. I suggest you open a support ticket and attach a small sample project.
Regards,Atanas Korchev
the Telerik team
When I try to present Grid view for the complex object (Employee) in the attached test project, the view completly fails to render with the following exeption:
System.ArgumentException was unhandled by user code
Message=Value cannot be null or empty.
Parameter name: name
Source=System.Web.Mvc ParamName=nameThe view here is Ajax binding with InForm editing mode. If I switched to InLine mode the Employee view renders correctely.
I do not know if I missing something here or It's a bug related to [TypeCoverter] objects with InForm editing mode grids!
I'm using 2010.2.825 MVC2 version, and I have attached complete stack trace for your refernce.
Appreciate your feedback.
The stacktrace shows that the name of some textbox is not set. Unfortunately I am not sure what is causing this exception. I would appreciate a sample project which demonstrates the exception. Then we will be able to investigate the cause of it.
All the best,Atanas Korchev
the Telerik team
Thank you for your reply,
I have attached a smaple project based on the orginal sample here.
I have noticed one more thing, removing the [TypeConverter] decoration for the Employee object will let the emplyee grid renders correctly.
Many thanks in advance.
I suggest you remove the TypeConverter as it is no longer necessary. It was used to provide support for nested editor templates but it didn't work 100% and introduced other problems (such as yours).
Kind regards,Atanas Korchev
the Telerik team
If I remove the TypeConverter, how would I support DropDownList editor template for the complex object?
It should work ok with inline mode at least. I tried it in the provided sample and the dropdown appeared correctly.
Regards,Atanas Korchev
the Telerik team
Anything else that you can advise aside from removing the type converter or using Inline mode?
I really need a dropdown list in GridEdit.InForm
Regards,
Junie
I have a blog post discussing that problem: Using nested complex objects with ASP.NET MVC editor templates. You can check it out.
Regards,Atanas Korchev
the Telerik team
Thanks a lot for the blog that you have provided. I was able to still use the Telerik dropdown by creating a Custom Editor template for my model.
Thank again!