MVC 4 version of NerdDinner has binding issue when I create a dinner

3.6k Views Asked by At

If you goto

http://nerddinner.codeplex.com/SourceControl/changeset/view/b1a032d1532b

Get the MVC4 version. Run it. Host a dinner. Click Create I always get this error (screenshot)

It is one of the main reference apps I want to use to help me learn so if anyone know what I am missing please tell me

I don't know if the screenshot worked but the error is :

IndexOutOfRangeException in this piece of code on the LatLongStr

public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
        if (valueProviderResult != null)
        {
            string[] latLongStr = valueProviderResult.AttemptedValue.Split(',');

            string point = string.Format("POINT ({0} {1})", latLongStr[1], latLongStr[0]);
            //4326 format puts LONGITUDE first then LATITUDE
            DbGeography result = DbGeography.FromText(point, 4326);
            return result;
        }
        return null;
    }

scree

1

There are 1 best solutions below

1
Pbirkoff On

That's probably because you're entering a value as the LatLongString without a , character

This command

string[] latLongStr = valueProviderResult.AttemptedValue.Split(',');

splits the given string if there is a , sign, to create the lat long.

Later, there is a reference to the two values

... latLongStr[1], latLongStr[0]);

However, if the value entered does not contain a , latLongStr only has 1 item, so latLongStr[1] is out of bounds.

You can prevent this by making sure a valid LatLong is entered.