如何添加数据 - 属性Html.BeginForm [英] How do I add data- attributes to Html.BeginForm

查看:127
本文介绍了如何添加数据 - 属性Html.BeginForm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面创建一个表单上移动网站上传图片。

  @using(Html.BeginForm(表格/,报价,FormMethod.Post,新{ENCTYPE =的multipart / form-data的}))

然而,因为它是使用jQuery移动,我已经支持Ajax使页面之间过渡是好的,平稳。这已经引起了我的形式不会上传的图像,你不能做文件上传与阿贾克斯的问题。我需要添加属性数据AJAX =FALSE这种形式,以便它让我的文件上传。

有谁知道我是如何做到这一点,因为我试过的多种变化以下,但不能得到它的工作:

  @using(Html.BeginForm(表格/,报价,FormMethod.Post,新{ENCTYPE =多部分/格式数据,数据AJAX= 假}))


解决方案

的技巧是使用下划线代替连字符:

 新{ENCTYPE =的multipart / form-data的data_ajax =假}

连字符不允许作为一个C#标识符的一部分。 MVC框架会自动转换下划线。

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" }))

解决方案

The trick is to use the underscore instead of the hyphen:

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

The hyphen is not allowed as part of a c# identifier. The MVC framework translates the underscore automatically.

这篇关于如何添加数据 - 属性Html.BeginForm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆