0

My ViewModel is as follows:

public class ClassificationCalculatorIndexViewModel
{
    public bool PlacementYear { get; set; }
    public int[] Credit { get; set; } // List of Integers
    public int selectedCredit { get; set; } // Somewhere to store selected integer
    public List<YearOfStudy> StudyYear { get; set; }
}   

I am struggling to bind the Integer array to a DropDownList helper object in my Razor view, I am doing the following:

@Html.DropDownListFor(Model.selectedCredit, Model.Credit)

But getting errors, I tried Googling, but found nothing of the same nature :(

2
  • What is the error you are getting? Commented Dec 24, 2012 at 15:09
  • The type arguments for method DropDownListFor<> cannot be inferred from the usage, try specifying the type arguments explicitly Commented Dec 24, 2012 at 15:13

2 Answers 2

4

I think you need drop down for selectedCredit filled with items from Credit property:

@Html.DropDownListFor(m => m.selectedCredit, new SelectList(Model.Credit))
Sign up to request clarification or add additional context in comments.

Comments

0

You need to create a SelectList object with the content of your int[].

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.