Question

This error message is driving me nuts.

I'm getting it when using Html.ListBox and Html.DropDownList HtmlHelpers with ASP.NET MVC v1.0. Populating the lists works OK - I can view them, etc - but when I go to create a new record in the Model using the FormCollection passed into the Controller to get the selected value, this error occurs. I've tried several different configurations and code arrangements as per several other posts on this matter - no joy.

Hopefully someone can tell me whether this is a known issue or not so as I can move on with my life! Would prefer not to have to post code if necessary, but can do if requested.

Oh, and a suggested workaround/solution would be nice too ;-)

TIA!

Bernard.


Ok, quick update, I've posted three comments to responses below clearing up details as to what I'm up to here.

I now have another issue to share - I've tried ScottGu's alternative recommended approach - implementing a ModelView. So, when I do this it's basically the same scenario, but I get an "Object reference not set to an instance of an object." error at the same place that I was getting "There is no ViewData item with the key 'Blah' of type 'IEnumerable'.".

I'm starting to thing that this is perhaps something to do with the way the EF works...

Was it helpful?

Solution

Ok, sooo I'm clearly an EF/MVC noob...

Although the issue was solved by my actually implementing proper exception management...the exception message (when I actually started catching it) was "The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects.". So I'm using the same ObjectContext for all data access now, and things are back on track.

Thanks for caring, I'll have a smarter question next time - promise!

Bernard.

OTHER TIPS

Not knowing how you are coding this will be hard for people to identify the problematic area. Have a read of this forum thread - further down has a similar error to you.

http://forums.asp.net/p/1320426/2623986.aspx

You can again bind your select list in the according post method where validation occurs. For example you have an error inside the create view of the controller than you can again bind dropdown list in create post method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top