locked
Problem while binding data to select list. RRS feed

  • Question

  • Hi,

    I have one ViewBag which has list in anonymous type 

    like {Text="Apple",Value=1}.

    But when i bind it with select list it give me a error "{"'object' does not contain a definition for 'Value'"}".

    my select list is below:

    <select multiple="multiple" id="Advocates" name="Advocates">
    <%foreach (var item in ViewBag.Advocates)
        { %>
              <option value="<%:(item.Value) %>"><%:(item.Text)%></option>
         <%} %>
    </select>

    Can any one suggest a answer for this problem.

    Thanks!

    Wednesday, November 15, 2017 10:10 AM