views:

147

answers:

1

Hi, I have a dropdown list on an ASP.NET MVC project that I am pretty sure is not binding to my model because of my nhibernate mapping. I have tried many variations on the asp mvc side resulting in this post here. MVC side of things seems fine I believe the issue may be that my object is trying to bind, but my mapping is out of whack.

My mapping is:

<many-to-one name="Project" lazy="false"
       class="AgileThought.ERP.Domain.Property.Project"
       column="ProjectGUID" />

My View gives an error saying that the GUID from the dropdownList selected value is not valid. Which I think may be that it is trying to push the GUID into my related project object. The value 'fd38c877-706f-431d-b624-1269184eeeb5' is invalid.

My related project list binds to the dropdown list just fine, it is just not binding to my models Project entity.

Does the related Project entity need to know about its relationship? Its really just a lookup list.

Many thanks for your time and best regards, Rod

+2  A: 

You'd probably need a custom binder that can essentially do this...

entity.Project = session.Load<Project>(selectedValue);

I think Sharp Arch has something like this...check out this + helper method.

If you want to keep it simple, maybe just do it manually.

dotjoe
Thanks dotjoe, I am able to manually populate it the project, I was hoping to bind it to the model.Im really not sure if the issue is with nhybernate or MVC.Im essentially trying to get a dropdownlist for to bind to the model.Project property like textboxes do.
Rod McLeay
Hi dotjoe, do i assign this in the controller?Rod
Rod McLeay
Sure, if going manual route, then the controller would be the place to do it. If you went with a custom binder, I think you'd need to have a ISession available outside the controller action.
dotjoe