-1

I have a dropdownlist that is working just fine, but when I have add a CKEditor (ckeditor-standard 4.5.7) to handel EditorFor helper I'm getting this error:

The ViewData item that has the key 'OccupationId' is of type 'System.Int32' but must be of type 'IEnumerable'.

Removing the CkEditor solve this error but I do need it, relevant code (from view)

    <div class="form-group">
        @Html.LabelFor(model => model.rev.ReviewBody, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.rev.ReviewBody, new { htmlAttributes = new { @class = "form-control", @id = "RevBEditor" } })
            @Html.ValidationMessageFor(model => model.rev.ReviewBody, "", new { @class = "text-danger" })
        </div>
    </div>  <div class="form-group">
            @Html.LabelFor(model => model.sub.Occupation.OccupationDecription, "Occupation", htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownList("OccupationId", null, htmlAttributes: new { @class = "" })
                @Html.ValidationMessageFor(model => model.OccupationId, "", new { @class = "text-danger" })
            </div>
        </div><script src="~/Scripts/ckeditor/ckeditor.js"></script> 
     <script type="text/javascript"> CKEDITOR.replace('RevBEditor'); </script>
Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116
Danny
  • 301
  • 1
  • 4
  • 21
  • Please show us your action – Roman Marusyk Mar 09 '16 at 15:15
  • Hi, my controller ? I think it's irrelevant the error is in the view before hitting the controller post , the get is : ViewBag.OccupationId = new SelectList(db.occupation, "OccupationId", "OccupationDecription"); – Danny Mar 09 '16 at 15:20
  • Try to use something like: `@Html.DropDownListFor(x => x.ID, (SelectList)ViewBag.OccupationId, new Dictionary{{"class", "control-label col-md-2"}})` – Roman Marusyk Mar 09 '16 at 15:28
  • Thanks, @Html.DropDownListFor(x => x.OccupationId, (SelectList)ViewBag.OccupationId, new Dictionary { { "class", "control-label col-md-2" } }) , Yes, it is the same Error . – Danny Mar 09 '16 at 15:34
  • CKEditor has nothing to do with it. And in future do not ask a user to remove a correct answer. –  Mar 09 '16 at 21:37

1 Answers1

1

That's not because of CKEditor, that is happening because you did not give a data source to drop down

Varun Vasishtha
  • 461
  • 2
  • 9
  • thank you, but the fact is that when I remove ,it is working just fine ... – Danny Mar 09 '16 at 13:09