tags:

views:

157

answers:

2

Greetings,

I'm a bit of an MVC noob. I'm trying to create a simple application where a client logs in and votes on something. Nothing complicated. I have a strongly typed View where I pass a VoteModel class this class contains a collection of VoteStructures. The Vote structure just contains an (int) ID, a description, and if it's selected.

So in my view I have

<% foreach (var item in Model.votes) { %>
    <%= Html.RadioButton("Destination", item.ID, item.SelectedInd) + " " + item.Destination %> <br />
<% } %>

When I perform a POST to get the submitted results my action method takes the strongly typed ViewModel back but the original vote structures collection object isn't populated.

Why is that? And how to do I go about fixing this?

I really appreciate the help

Brian

A: 

If Model.votes is a list, you will need to look into handling IEnumerable in MVC 1 (more goodies). Usage has been significantly improved in MVC 2.

NickLarsen
A: 

Well, I can dig the selected radio button out of the Request.Form object. I'm betting there is a better solution but this does appear to work. As the previous answer points out this is better in MVC 2. If there is a better solution than this I'd appreciate it.

Thanks,

Brian

    [AcceptVerbs(HttpVerbs.Post)]
    public ViewResult Index(VoteModel oVM)
    {

        var ID = Request.Form["Destination"];
        if (ID != null)
        {
            //Moving on with life
        }    

        //just repost the same data since the client didn't make a selection
    }
Brian Kriesel
Well, this can be simplified by putting destination as a string property on the Viewmodel that way my Controller doesn't depend on the request.
Brian Kriesel