0

I have taken File > Project > New Project >Choose Template MVC >select MVC WebForm also when i am trying to code register view any Jquery It was not working.How could i solve this error.Error will show in dropdownlist.This is the error

    "The ViewData item that has the key 'Country' is of type 'System.String' but must be of type 'IEnumerable<SelectListItem>'.." 

==code Jquery==

 $(document).ready(function () {

        $("#dd_Country").change(function () {

            var countryId = $(this).val();

            $.getJSON("Account", "LoadStatesByCountryId", { Countryid: countryId },

                   function (classesData) {

                       var select = $("#ddState");

                       select.empty();

                       select.append($('<option/>', {

                           value: 0,

                           text: "Select a State"

                       }));

                       $.each(classesData, function (index, itemData) {

                               select.append($('<option/>', {

                               value: itemData.Value,

                               text: itemData.Text

                           }));

                       });

                   });
              });
          });

</script>*@ 

==this the code for dropdownlist==

 <div class="form-group">
            @Html.LabelFor(m => m.Country, new { @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.DropDownList("Country",null,"--Select Citizenship--", new { @class = "form-control" })
                @*@Html.DropDownListFor(m => m.Country, new SelectList(ViewBag.Countries as System.Collections.IEnumerable, "Id", "Name"),
                "Select a Country", new { id = "dd_Country", @class = "form-control" })*@

                @Html.ValidationMessageFor(model => model.Country, "", new { @class = "text-danger" })
            </div>
        </div>       
Guruprasad J Rao
  • 29,410
  • 14
  • 101
  • 200
  • Also you can refer **[this post here](https://stackoverflow.com/questions/34366305/the-viewdata-item-that-has-the-key-xxx-is-of-type-system-int32-but-must-be-o)** – Guruprasad J Rao Jun 07 '17 at 10:38
  • Problem is not only IEnumerable.First time I have registered It was successfull.When I have reenter the same value like same UserName or Email It gave me this type of error.Please help me in details @Guruprasad Rao – Smriti Sarkar Jun 07 '17 at 11:36

0 Answers0