(Html.BeginForm("Search", "YOUR CONTROLLER", null)
我有上述代码,它链接到注释的控制器方法,但我不必放置
(Html.BeginForm("Search", "YOUR CONTROLLER", FormMethod.Post)
好奇为什么这样,还没有完全被HTML.Beginform的所有细微差别完全包裹起来...
html.beginform进程method
参数使用下面显示的方法GetFormMethodString
:
public static string GetFormMethodString(FormMethod method)
{
switch (method)
{
case FormMethod.Get:
return "get";
case FormMethod.Post:
return "post";
default:
return "post";
}
}
因此,如果未提供方法值,则该方法默认为post
。
但是,值得一提的是,当您为第三参数指定null
时,您实际上并未将参数method
设置为null
,而您是针对具有RouteValueDictionary
作为第三Paramater的过载, not 有FormMethod
的那个。这是因为 method
不是一个无效的参数,而 RouteValueDictionary
是一个无效的对象。
Html.BeginForm("Search", "YOUR CONTROLLER", null)
调用过载:
public static MvcForm BeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, RouteValueDictionary routeValues);
Html.BeginForm("Search", "YOUR CONTROLLER", FormMethod.Post
调用过载:
public static MvcForm BeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method);
p>