public static MvcForm BeginForm(this HtmlHelper html, string controller = null, string action = null, Action <FormTag> config = null, object routeValues = null) { var form = new FormTag(); form.Method("POST"); if (controller.IsNullOrEmpty()) { controller = html.ViewContext.GetControllerName(); } if (action.IsNullOrEmpty()) { action = html.ViewContext.GetActionName(); } if (config != null) { config(form); } form.Action(UrlHelper.GenerateUrl(null, action, controller, new RouteValueDictionary(routeValues), html.RouteCollection, html.ViewContext.RequestContext, true)); form.NoClosingTag(); html.ViewContext.Writer.Write(form.ToString()); return(new MvcForm(html.ViewContext)); }
public void form_action_can_be_specified_via_constructor() { var tag = new FormTag("/user/create"); tag.ToString().ShouldEqual("<form id=\"mainForm\" method=\"post\" action=\"/user/create\">"); }
public void form_id_can_be_customized() { var tag = new FormTag().Id("other-form"); tag.ToString().ShouldEqual("<form id=\"other-form\" method=\"post\">"); }
public void form_method_can_be_customized() { var tag = new FormTag().Method("get"); tag.ToString().ShouldEqual("<form id=\"mainForm\" method=\"get\">"); }
public void form_tag_creates_the_opening_element_of_a_form_with_id_mainForm() { var tag = new FormTag(); tag.ToString().ShouldEqual("<form id=\"mainForm\" method=\"post\">"); }
public void form_action_can_be_specified() { var tag = new FormTag().Action("/user/create"); tag.ToString().ShouldEqual("<form method=\"post\" action=\"/user/create\">"); }