This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi: I have ran into an issue using Lightspeed entities as view models in a MVC app. I'm using the EntityModelBinder that has been provided here and it works well for simple entities. However, if you have a entity that contains a child entity, errors from the child entity don't seem to make it up to the ModelState to be displayed. The EntityModelBinder does gets called twice for the parent and child entities. Is there a trick to getting this to work? I would be nice to be able to use the built in entity validation if I can. I have no problem getting it to work with a custom view model. Sample code: Entities: class Parent : Entity { string Name { get; set; } Child SubInfo { get; set; } } class Child : Entity { string Name { get; set; } } HTML excerpt: <%: Html.TextBoxFor(e => e.Name) %>
<%: Html.ValidationMessageFor(e => e.Name)%> <%: Html.TextBoxFor(e => e.SubInfo.Name) %> <%: Html.ValidationMessageFor(e => e.SubInfo.Name)%> |
|
|
No, the EntityModelBinder currently only operates on the specific object and doesnt traverse down any relationships. Its certainly possible using reflection code to add in some support for traversing relationships but this may be a bit cumbersome for you. Two thoughts would be either looking at seeing if you can bend the DefaultModelBinder to achieve your aims, if you wanted to bind up the error handling you could do something similar to what was suggested in this post: http://www.mindscapehq.com/forums/Post.aspx?ThreadID=4093&PostID=14167 Alternatively we are about to push out some functionality with the v4 Beta which emits metadata about your LightSpeed model which would allow you to make the changes to the EntityModelBinder without having to resort to reflection. If using that is an option for you then that would probably be a good option.
Jeremy |
|
|
Thanks Jeremy. I am using version 2 of the EntityModelBinder. As you stated it doesn't know about relationships so the errors are added without taking them into account. I may put knowledge of the entity model in the binder for the time being to get around this problem. Would you be providing a new (V3) of the EntityModelBinder when you push out the next Beta? Thanks, Scott |
|
|
Yes, I will be definitely be updating the ModelBinder - the beta is actually updated daily via nightlies but since the ModelBinder is part of the samples we wont be pushing that out probably until we finalise 4.0. That said I will post you the updated code once we have made the changes and the Metadata assembly is out in the nightlies for you to use.
Jeremy |
|