[英]asp.net mvc c# enctype
我如何只能在中添加enctype
<% using (Html.BeginForm()) {%>
如前所述,您還需要指定操作和方法(無論如何,BeginForm()都會為您添加此操作)。
要添加編碼類型,您至少需要使用重載,該重載使您可以指定mvc操作,控制器和表單方法,如下所示:
using(Html.BeginForm("Index", "Home", FormMethod.Post, new{enctype="multipart/form-data"}))
你不能
表單元素需要一個action
和method
屬性。
見規格 :
<!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
屬性和method
( GET
或POST
)一樣是#REQUIRED 。
這就是Html.BeginForm()
自動添加它們的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.