Closed profnimrod closed 9 years ago
The whole list of options is not going to be posted back to the server on submit. You can easily verify this in Chrome Dev tools in the network tab.
However, if you still want to use ViewBag, just specify its type:
@f.FormGroup().DropDownListFor(x => x.Guid, (IEnumerable<SelectListItem>)ViewBag.ListItems).Label().LabelText("Generic Type")
Many thanks for your rapid response as always Dmitry. I was so close to solving it just as you posted. I should have given it a little more time before troubling you. Apols.
Thanks also for the note about the whole list being posted back to the server. My mistake. Using ViewBag or ViewData just happens to be convenient in this case.
no problem, good luck!
I have a List in my ViewBag. It contains many items so I'd rather not include it in the Model as I don't want it posted back to the server when the form is submitted. I have the following:
The error I get says:
I'm assuming this is referring to the fact that the ViewBag is a dynamic type. Is there a way to make this work without having to include my ListItems in the view's model? I want the selected value to populate x.Guid.