开发者

MVC2: Assign a name to the form using Html.BeginForm()

I am using t开发者_如何学Pythonhe following method overload for the Html.BeginForm() method to create a form in my view:

public static MvcForm BeginRouteForm(this HtmlHelper htmlHelper, RouteValueDictionary routeValues);

I would like to specify the form name. But I can't see any parameter that will allow me to do so.

Any work-around for this?

Thanks :)


This is the overload you need:

public static MvcForm BeginRouteForm(
    this HtmlHelper htmlHelper,
    string routeName,
    Object routeValues,
    FormMethod method,
    Object htmlAttributes
)

MSDN link


The following overload can be used:

public static MvcForm BeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, RouteValueDictionary routeValues, FormMethod method, IDictionary<string, object> htmlAttributes);

by substituing null for actionName and controllerName and appropriate FormMethod.

e.g. Instead of:

<% Html.BeginForm(Html.MyRouteValues(Model.MyFilterOptions, Model.MySortOptions, Model.Page)); %>

I am using:

<% Html.BeginForm(null, null, Html.MyRouteValues(Model.MyFilterOptions, Model.MySortOptions, Model.Page), FormMethod.Post, new { @name = "myForm" }); %>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜