Asp.net MVC - Model binding image button

Posted by big dave on Stack Overflow See other posts from Stack Overflow or by big dave
Published on 2010-05-06T11:06:09Z Indexed on 2010/05/06 11:18 UTC
Read the original article Hit count: 192

Filed under:
|
|
|

I've got a very complex form and i'm using the MVC model binding to capture all the information

I've got it set up to capture all the different submissions that can happen as there are about 10 different submit buttons on the form, and there are also 2 image buttons

I tried to get a bit clever (or so i thought) with capturing the image button submissions, and have created a child class so that i can capture the x value that's returned

public class ImageButtonViewData {
    public int x { get; set; }
    public string Value { get; set; }
}

The parent class looks something like this

public class ViewDataObject {
    public ImageButtonViewData ImageButton { get; set; }

    public ViewDataObject(){
        this.ImageButton = new ImageButton();
    }
}

The html for the image button then looks like

<input type="image" id="ViewDataObject_ImageButton" name="ViewDataObject.ImageButton" />

This works fine in all browsers except for Chrome.

When i debug it in chrome, the Request.Form object contains the values that i would expect, but after the model binding has occurred, the ImageButton property on the ViewDataObject has been set to null

The only difference that i can see between the submission values is that Chrome passes the x as lower case (ViewDataObject.ImageButton.x) and IE passes it as upper case (ViewDataObject.ImageButton.X) but i didn't think that model binding took any notice of casing on property names

Does anyone have any ideas ?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about mvc