weixin_33694172 2013-04-10 21:09 采纳率: 0%
浏览 16

表格提交问题

I am developing an ASP.Net MVC application and I have form containing a file upload HTML element and a submit button. When the user first goes to the view, I have javascript code automatically triggering the click event on the file upload HTML element so the user does not have to press the button themselves. This is for convenience and the way I want it to be, but when I trigger the button click automatically it is causing the following issue: I have to press the Submit button twice in order to submit the form. The first press clears the text in the file upload HTML element and the second press submits the form. Can anyone explain why this is happening and how I can get it not to do this?

Note: The form is explicitly set not to use Ajax because I am uploading an image and from my understanding you cannot upload images via Ajax, so I turn that off with data-ajax = "false" in my form HTML attributes. Having this set to false is related to the issue I am having. If I submit via ajax, I only have to press the submit button once. If I do not use ajax, I need to press twice.

Here is essential code showing issue:

@Using Html.BeginForm("Document", "NewDocument", Model, FormMethod.Post, New With {.enctype = "multipart/form-data", .data_ajax = "false", .id="submitimage-form"})

@<input type="file" id="fileInput" name="fileInput" style="visibility:hidden;" />   

@<input type="submit" id="accept2" value="Accept" data-mini="true" data-theme="b" data-icon="check"/>
End Using

<script>

// Do once after DOM is loaded for the page
$(document).bind("pageinit", function () {
    $("#fileInput").click();
});

</script>
  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器