.NET中的html.beginform-第三个参数似乎是占用或属性的


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

最新更新