2

I am a newer fresher in ASP.Net MVC.

I want to create a drop down list control. That is my member class.

Public Class Member

    Public Property MemberID As Integer
    Public Property MemberName As String

End Class

This is my controller class.

Function Login() As ActionResult
    Dim Members As List(Of Member) = HttpContext.Application("Members")

    ViewData("Members") = New SelectList(Members)

    Return View()
End Function

In my view class.

 @Html.DropDownList("Members")

But the drop down shows members...members...members. How can I fix it? Thanks all.

1

2 Answers 2

2

In your controller action you could specify the names of the properties on your model to be used as value and text for the dropdown:

ViewData("Members") = New SelectList(Members, "MemberID", "MemberName")
Sign up to request clarification or add additional context in comments.

Comments

1

Try this instead of your code

@Html.DropDownList("SelectedMember", 
    new SelectList((System.Collections.IEnumerable) ViewData["Members"], "MemberId", "MemberName"))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.