开发者

EF 4.0 - Save creates duplicates in TEST environment, but not in DEV

开发者 https://www.devze.com 2023-04-10 20:06 出处:网络
FINAL EDIT If you are looking at this question, please see the answer I posted below. The original problem was not with EF, it was with my JQuery implementation.

FINAL EDIT If you are looking at this question, please see the answer I posted below. The original problem was not with EF, it was with my JQuery implementation.

EDIT: I have confirmed that this is only happening in IE (specifically IE 7). I don't see the same behavior in Chrome. I haven't tested Fi开发者_开发问答refox yet, but we don't support FF in our environment, so I'm not as worried about it.)

Before I post a bunch of code, I just wanted to put this out there to see if anyone else has ever experienced anything similar, and if so, what their culprit was.

I have code in an MVC project that creates a new entity. The code works as expected in my local environment. However, when I push the code out to our test server environment, the same code creates two records upon save.

I have verified that the database schemas are identical, so I have eliminated that as a possible cause.

Has anyone else ever experienced anything like this? If so, what did you do to fix the problem?

Thanks


I finally tracked the issue down to a bug in some javascript. The problem had nothing to do with Entity Framework or MVC. I have some jQuery code that helps me add icons to submit buttons, and in IE it was causing the submit to happen twice.

In case anyone is interested, here is the offending code:

$('input[type="submit"]').each(function () {
    $(this).hide().after('<button>').next().button({
        icons: { primary: $(this).attr('icon') },
        label: $(this).val()
    }).click(function (event) {
        event.preventDefault();
        $(this).prev().click();
        return false;
    });
});

This caused no problems in Chrome, but in IE the submit buttons were firing twice. To fix it, i added onclick="return false;" to my input tags, and the problem went away.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号