繁体   English   中英

ASP.NET MVC C#编码类型

[英]asp.net mvc c# enctype

我如何只能在中添加enctype

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

如前所述,您还需要指定操作和方法(无论如何,BeginForm()都会为您添加此操作)。

要添加编码类型,您至少需要使用重载,该重载使您可以指定mvc操作,控制器和表单方法,如下所示:

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

你不能

表单元素需要一个actionmethod属性。

规格

<!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 --
  >

从DTD片段中可以看到, action属性和methodGETPOST )一样是#REQUIRED

这就是Html.BeginForm()自动添加它们的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM