Error with DropDownList when CKEditor is also in u

2019-09-21 01:43发布

问题:

This question already has an answer here:

  • The ViewData item that has the key 'XXX' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>' 5 answers

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>

回答1:

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