Asp.net-mvc – Html.BeginForm and adding properties

asp.net-mvc

How would I go about adding enctype="multipart/form-data" to a form that is generated by using <% Html.BeginForm(); %>?

Best Answer

As part of htmlAttributes,e.g.

Html.BeginForm(
    action, controller, FormMethod.Post, new { enctype="multipart/form-data"})

Or you can pass null for action and controller to get the same default target as for BeginForm() without any parameters:

Html.BeginForm(
    null, null, FormMethod.Post, new { enctype="multipart/form-data"})