How do I add data- attributes to Html.BeginForm

后端 未结 2 1228
伪装坚强ぢ
伪装坚强ぢ 2021-02-05 01:21

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

@using (Html.BeginForm(\"Form/\", \"Quote\", FormMethod.Post, new { enctype = \"multipa         


        
相关标签:
2条回答
  • 2021-02-05 02:00

    You can use another overload:

    @using (Html.BeginForm("Form", "Quote", FormMethod.Post, new Dictionary<string, object> { { "enctype", "multipart/form-data" }, { "data-ajax", "false"} })) 
    
    0 讨论(0)
  • 2021-02-05 02:12

    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.

    0 讨论(0)
提交回复
热议问题