views:

146

answers:

1

I would like to pass a date from a drop down list to my ID in the Html.BeginForm. This is what I have so far.

<%using (Html.BeginForm("Inquiry", "Billing", new { Date = ????? }, FormMethod.Post))


        <select id="myList" name="myList" >
        <option>Term - Balance</option>
        foreach (var item in Model.Term)
          { %>                             
        <option value="/<%=String.Format("{0:yyyyMMdd}", item.Date) %>" >
        <%=item.Date.ToShortDateString()%> - <%=String.Format("{0:C}", (item.Balance))%></option>
        <% } %>            
        </select>

Any suggestions?

+1  A: 

You can add additional attributes to the BeginForm method like this:

 <% using (Html.BeginForm("Inquiry", "Billing", 
                             FormMethod.Post, new { id = myDate.ToString() }))
       { %>

...

    <%} %>

If you're asking how to make the form ID change when a user changes the selection on a dropdownlist on the form, then you'll need to use javascript for that. The code above only runs once at render time, so if your myDate variable isn't set by then, then you can't get it on the server side.

womp