36

I use the following to create a form to upload images on a mobile site.

@using (Html.BeginForm("Form/", "Quote", FormMethod.Post, new { enctype = "multipart/form-data" }))

However as it is using jQuery mobile, I have enabled Ajax so that transition between pages is nice and smooth. This has caused the problem that my form won't upload the images as you cannot do file uploads with ajax. I need to add the attribute data-ajax="false" to this form in order for it to allow my file uploads.

Does anyone know how I do this as I tried multiple variations of the following but couldn't get it to work:

@using (Html.BeginForm("Form/", "Quote", FormMethod.Post, new { enctype = "multipart/form-data", "data-ajax" = "false" }))
4

2 回答 2

69

诀窍是使用下划线而不是连字符:

new { enctype = "multipart/form-data", data_ajax = "false" }

连字符不允许作为 ac# 标识符的一部分。MVC 框架会自动翻译下划线。

于 2013-07-23T13:39:33.430 回答
20

您可以使用另一个重载:

@using (Html.BeginForm("Form", "Quote", FormMethod.Post, new Dictionary<string, object> { { "enctype", "multipart/form-data" }, { "data-ajax", "false"} })) 
于 2013-07-23T13:39:11.187 回答