views:

9

answers:

1

Hi New to stackoverfloow and in need of help, when submitting a form using ajax with javascript disabled, i get the following error:

Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type '<>f__AnonymousType11[System.String]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1

My code is:

public PartialViewResult SearchLocation(string strSearch)
        {
            if (Request.IsAjaxRequest())
            {
                int intNumberOfResults = Weather.GetCity(strSearch).Count();
                if (intNumberOfResults == 0)
                {
                    ViewData["intNumberOfWeatherLocations"] = "No Locations Found";
                }
                else
                {
                    if (intNumberOfResults == 1)
                    {
                        ViewData["intNumberOfWeatherLocations"] = intNumberOfResults.ToString() + " " + "location found for:" + " " + strSearch.ToString();
                    }
                    else
                    {
                        ViewData["intNumberOfWeatherLocations"] = intNumberOfResults.ToString() + " " + "locations found for:" + " " + strSearch.ToString();
                    }
                }

                var model = Weather.GetCity(strSearch);
                return PartialView("WeatherSearch", model);
            }
            else
            {
                return PartialView("WeatherSearch", new { strSearch = strSearch });
            }
        }

I'm trying to follow along with a book i'm reading and modify the code to suit my needs. Any help would be appreciated John

A: 

Hi

Anyone know how to solve this problem

Thanks

MVC Code