开发者

asp.net mvc c# enctype

how can i add enctype 开发者_开发问答only in

<% using (Html.BeginForm()) {%>


As said, you need to also have the action and method specifid (BeginForm() adds this in for you anyway).

To add the encoding type, you need to at least use the overload which makes you specify the mvc action, controller and form method, like so:

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


You can't.

A form element requires an action and method attributes.

See the spec:

<!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM) -- interactive form -->
<!ATTLIST FORM
  %attrs;                              -- %coreattrs, %i18n, %events --
  action      %URI;          #REQUIRED -- server-side form handler --
  method      (GET|POST)     GET       -- HTTP method used to submit the form--
  enctype     %ContentType;  "application/x-www-form-urlencoded"
  accept      %ContentTypes; #IMPLIED  -- list of MIME types for file upload --
  name        CDATA          #IMPLIED  -- name of form for scripting --
  onsubmit    %Script;       #IMPLIED  -- the form was submitted --
  onreset     %Script;       #IMPLIED  -- the form was reset --
  accept-charset %Charsets;  #IMPLIED  -- list of supported charsets --
  >

As you can see from the DTD fragment, the action attribute is #REQUIRED as is the method (GET or POST).

This is why Html.BeginForm() adds them automatically.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜