public void BeginFormWithClientValidationEnabled() { // Arrange StringWriter writer; HtmlHelper htmlHelper = GetFormHelper(out writer); htmlHelper.ViewContext.ClientValidationEnabled = true; htmlHelper.ViewContext.FormContext = null; FormContext defaultFormContext = htmlHelper.ViewContext.FormContext; // Act & assert - push MvcForm theForm = htmlHelper.BeginForm(); Assert.NotNull(htmlHelper.ViewContext.FormContext); Assert.NotEqual(defaultFormContext, htmlHelper.ViewContext.FormContext); Assert.Equal("form_id", htmlHelper.ViewContext.FormContext.FormId); // Act & assert - pop theForm.Dispose(); Assert.Equal(defaultFormContext, htmlHelper.ViewContext.FormContext); Assert.Equal(@"<form action=""/some/path"" id=""form_id"" method=""post""></form><script type=""text/javascript""> //<![CDATA[ if (!window.mvcClientValidationMetadata) { window.mvcClientValidationMetadata = []; } window.mvcClientValidationMetadata.push({""Fields"":[],""FormId"":""form_id"",""ReplaceValidationSummary"":false}); //]]> </script>", writer.ToString()); }
public static MvcForm BeginTokenForm(this HtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method, object htmlAttributes) { var mvcForm = htmlHelper.BeginForm(actionName, controllerName, method, htmlAttributes); htmlHelper.ViewContext.Writer.Write(htmlHelper.AntiForgeryToken().ToHtmlString()); return(mvcForm); }
public static MvcForm BeginTokenForm(this HtmlHelper htmlHelper, string actionName, string controllerName, RouteValueDictionary routeValues, FormMethod method) { var mvcForm = htmlHelper.BeginForm(actionName, controllerName, routeValues, method); htmlHelper.ViewContext.Writer.Write(htmlHelper.AntiForgeryToken().ToHtmlString()); return(mvcForm); }
public static MvcForm BeginTokenForm(this HtmlHelper htmlHelper) { var mvcForm = htmlHelper.BeginForm(); htmlHelper.ViewContext.Writer.Write(htmlHelper.AntiForgeryToken().ToHtmlString()); return(mvcForm); }
public static MvcForm BeginTokenForm(this HtmlHelper htmlHelper, RouteValueDictionary routeValues) { var mvcForm = htmlHelper.BeginForm(routeValues); htmlHelper.ViewContext.Writer.Write(htmlHelper.AntiForgeryToken().ToHtmlString()); return(mvcForm); }
public void BeginFormWithClientValidationEnabled() { // Arrange StringWriter writer; HtmlHelper htmlHelper = GetFormHelper(out writer); FormContext originalContext = new FormContext(); htmlHelper.ViewContext.ClientValidationEnabled = true; htmlHelper.ViewContext.FormContext = originalContext; // Act & assert - push MvcForm theForm = htmlHelper.BeginForm(); Assert.IsNotNull(htmlHelper.ViewContext.FormContext); Assert.AreNotEqual(originalContext, htmlHelper.ViewContext.FormContext, "FormContext should have been set to a new instance."); Assert.AreEqual("form_id", htmlHelper.ViewContext.FormContext.FormId); // Act & assert - pop theForm.Dispose(); Assert.AreEqual(originalContext, htmlHelper.ViewContext.FormContext, "FormContext was not properly restored."); Assert.AreEqual(@"<form action=""/some/path"" id=""form_id"" method=""post""></form><script type=""text/javascript""> //<![CDATA[ if (!window.mvcClientValidationMetadata) { window.mvcClientValidationMetadata = []; } window.mvcClientValidationMetadata.push({""Fields"":[],""FormId"":""form_id"",""ReplaceValidationSummary"":false}); //]]> </script>", writer.ToString()); }
public static MvcForm BeginForm <TController>(this HtmlHelper htmlHelper, Expression <Action <TController> > action, FormMethod method, IDictionary <string, object> htmlAttributes) where TController : Controller { RouteValueDictionary rvd = ExpressionHelper.GetRouteValuesFromExpression(action); return(htmlHelper.BeginForm(null, null, rvd, method, htmlAttributes)); }
public static MvcForm BeginForm <TController>(this HtmlHelper html, Expression <Func <TController, object> > action, FormMethod method = FormMethod.Post, object attributes = null) { //Contract.Requires( html != null ); //Contract.Requires( action != null ); return(html.BeginForm(action.MemberName(), typeof(TController).AssemblyQualifiedName, action.CallParameters().CoerceRouteValues(), method, attributes.ToRouteValues())); }
public static MvcHtmlString NewCommentaireFormHelper <TModel, TPropertyTitre, TPropertyCommentaire>(this HtmlHelper <TModel> self, Expression <Func <TModel, TPropertyTitre> > expTitre, Expression <Func <TModel, TPropertyCommentaire> > expCommentaire, int idHotel, int?idCommentaireReference) { // le <div> externe var divTag = new TagBuilder("div"); divTag.AddCssClass("FormulaireCommentaire"); divTag.AddCssClass("form-group"); var labelTitre = self.LabelFor(expTitre); var inputTitre = self.TextBoxFor(expTitre, new { @class = "form-control" }); var labelCommentaire = self.LabelFor(expCommentaire); var inputCommentaire = self.TextAreaFor(expCommentaire, new { @class = "form-control" }); var stringHiddenIdCommentaireReference = "<input type=\"hidden\" name=\"IdCommentaire\" value=\"" + idCommentaireReference + "\"/>"; var stringButtonSubmit = "<button type=\"submit\" class=\"btn-info btn-lg\" id=\"PostBtn\">Poster</button>"; divTag.InnerHtml = labelTitre.ToString() + inputTitre.ToString() + labelCommentaire.ToString() + inputCommentaire.ToString() + stringButtonSubmit + stringHiddenIdCommentaireReference; using (self.BeginForm("Comment", "Hotel", new { id = idHotel }, FormMethod.Post, new { id = "FormulaireCommentaire" })) { self.ViewContext.Writer.Write(divTag.ToString()); } return(new MvcHtmlString("")); }
public static MvcForm BeginForm(this HtmlHelper htmlHelper, String actionName, String controllerName, Hash values) { return(htmlHelper.BeginForm(actionName, controllerName, HashHelper.ToRouteValueDictionary(values))); }
public static MvcForm BeginFormMultipart(this HtmlHelper helper) { string controllerName = helper.ViewContext.RouteData.Values["controller"].ToString(); string actionName = helper.ViewContext.RouteData.Values["action"].ToString(); return(helper.BeginForm(actionName: actionName, controllerName: controllerName, method: FormMethod.Post, htmlAttributes: new { enctype = "multipart/form-data" })); }
public MvcForm BeginForm(HtmlHelper htmlHelper) { var dataHelper = ((Sagromin.Helpers.AppWebViewPage <dynamic>)htmlHelper.ViewDataContainer).Data; var autoTargetParams = dataHelper.CreateAutoTargetAjaxAttributes().ToString(); var htmlAttributes = new RouteValueDictionary(HtmlAttributes); if (!String.IsNullOrWhiteSpace(autoTargetParams)) { foreach (var autoTargetParam in autoTargetParams.Split(' ')) { if (String.IsNullOrWhiteSpace(autoTargetParam)) { continue; } var attribute = autoTargetParam.Substring(0, autoTargetParam.IndexOf("=")); var value = autoTargetParam.Substring(attribute.Length + 2, autoTargetParam.Length - attribute.Length - 3); htmlAttributes[attribute] += value; } htmlAttributes["data-ajax-success"] = "AutoTargetAjaxCerrarModal"; htmlAttributes["data-parsley-validate"] = ""; htmlAttributes["novalidate"] = ""; //="" ="" } return(htmlHelper.BeginForm(ActionName, ControllerName, new RouteValueDictionary(RouteValues), Method, htmlAttributes)); }
/// <summary> /// SmartLibSecureForm. /// </summary> /// <param name="helper">helper.</param> /// <param name="actionName">actionName.</param> /// <param name="controllerName">controllerName.</param> /// <param name="htmlAttributes">htmlAttributes.</param> /// <returns>MvcForm.</returns> public static MvcForm SmartLibSecureForm(this HtmlHelper helper, string actionName, string controllerName, object htmlAttributes) { var form = helper.BeginForm(actionName, controllerName, FormMethod.Post, htmlAttributes); helper.ViewContext.Writer.Write(helper.AntiForgeryToken().ToHtmlString()); return(form); }
/// <summary> /// SmartLibSecureForm /// </summary> /// <param name="helper">HtmlHelper</param> /// <returns>MvcForm</returns> public static MvcForm SmartLibSecureForm(this HtmlHelper helper) { var form = helper.BeginForm(); helper.ViewContext.Writer.Write(helper.AntiForgeryToken().ToHtmlString()); return(form); }
public static MvcForm BeginForm(this HtmlHelper htmlHelper, String actionName, String controllerName, FormMethod method, Hash htmlAttributes) { return(htmlHelper.BeginForm(actionName, controllerName, method, HashHelper.ToStringKeyDictinary(htmlAttributes))); }
public ExampleConfigurator PostTo(string action, string controller) { string theme = htmlHelper.ViewContext.HttpContext.Request.Params["theme"] ?? "sunset"; form = htmlHelper.BeginForm(action, controller, new { theme }); return(this); }
/// <summary> /// 扩展 BeginForm 方法,只需要 一个 htmlAttributes 属性参数即可; /// </summary> /// <param name="html"></param> /// <param name="htmlAttributes">必须为 IDictionary<string, Object> 类型, </param> /// <param name="method">默认为Post;</param> /// <returns></returns> public static MvcForm BeginForm(this HtmlHelper html, IDictionary <string, Object> htmlAttributes, FormMethod method = FormMethod.Post) { string actualAction = (string)html.ViewContext.RouteData.Values["action"]; string actualController = (string)html.ViewContext.RouteData.Values["controller"]; return(html.BeginForm(actualAction, actualController, method, htmlAttributes)); }
public static MvcForm BeginSecureForm(this HtmlHelper html, string action, string controller) { var form = html.BeginForm(action, controller); html.ViewContext.Writer.Write(html.AntiForgeryToken().ToHtmlString()); return(form); }
private static MvcForm BeginForm <T, T1>(this HtmlHelper helper, Expression <Func <T, T1> > expression, FormMethod formMethod, object routeValues) { var controller = typeof(T).Name.Replace("Controller", string.Empty);//TODO - поменять реализацию var action = ((MethodCallExpression)expression.Body).Method.Name; return(helper.BeginForm(action, controller, formMethod, routeValues)); }
private void Init(HtmlHelper html, string actionName = null, string controllerName = null, object routeValues = null, FormMethod method = FormMethod.Post, object htmlAttrs = null, FormType? formType = null) { var attrs = new HtmlAttributes(htmlAttrs); if (formType != null) attrs["class"] += "form-" + formType.ToString().ToLower(); if (html == null) return; _form = html.BeginForm(actionName, controllerName, new RouteValueDictionary(routeValues), method, attrs.ToDictionary()); }
public static MvcForm BeginForm <T>(this HtmlHelper html, Expression <Func <T, object> > expression, FormMethod formMethod = FormMethod.Post, object htmlAttributes = null) where T : ControllerBase { var controllerName = ActionExpressionHelper.GetControllerNameFromExpression(expression); var actionName = ActionExpressionHelper.GetActionNameFromExpression(expression); var routeValueDictionary = ActionExpressionHelper.GetRouteValuesFromExpression(expression); return(html.BeginForm(actionName, controllerName, routeValueDictionary, formMethod, htmlAttributes?.ToDictionary())); }
public static MvcForm BeginForm <TController>(this HtmlHelper helper, Expression <Action <TController> > action, object htmlAttributes = null) where TController : Controller { var attrs = htmlAttributes == null ? new Dictionary <string, object>() : htmlAttributes.ToDictionary(); attrs.Add("action", helper.BuildUrlFromExpression(action)); return(helper.BeginForm(null, null, FormMethod.Post, attrs)); }
public static MvcForm DefaultForm <T>(this HtmlHelper helper, Expression <Action <T> > selector, object htmlAttributes) where T : Controller { var dictionary = new RouteValueDictionary(htmlAttributes); return (helper.BeginForm(selector, FormMethod.Post, dictionary)); }
public static MvcForm BeginForm(this HtmlHelper htmlHelper, string cssClass) { string actionName = (string)htmlHelper.ViewContext.RouteData.Values["action"]; string controllerName = (string)htmlHelper.ViewContext.RouteData.Values["controller"]; IDictionary <string, object> htmlAttributes = new Dictionary <string, object>(); htmlAttributes.Add("class", cssClass ?? string.Empty); return(htmlHelper.BeginForm(actionName, controllerName, FormMethod.Post, htmlAttributes)); }
public static MvcForm BeginForm <TCtrl>(this HtmlHelper helper, Expression <Action <TCtrl> > expression, object rootValues = null, FormMethod method = FormMethod.Post, object htmlAttributes = null) where TCtrl : Controller { var ctrl = typeof(TCtrl).Name.Replace("Controller", ""); var action = ((MethodCallExpression)expression.Body).Method.Name; return(helper.BeginForm(action, ctrl, rootValues, method, htmlAttributes)); }
public static MvcForm BeginForm(this HtmlHelper htmlHelper, string actionName = null, string controllerName = null, object routeValues = null, FormMethod method = FormMethod.Post, string accept = null, string acceptCharset = null, string cssClass = null, string dir = null, string encType = null, string id = null, string lang = null, string name = null, string style = null, string title = null) { return(htmlHelper.BeginForm( actionName, controllerName, routeValues as RouteValueDictionary ?? new RouteValueDictionary(routeValues), method, FormAttributes(accept, acceptCharset, cssClass, dir, encType, id, lang, name, style, title))); }
public static MvcForm BeginSearchForm(this HtmlHelper helper, string actionName) { var controllerName = helper.ViewContext.Controller.ControllerContext.RouteData.Values["controller"].ToString(); return(helper.BeginForm(actionName, controllerName, FormMethod.Post, new { @class = "no-dirty" })); }
public static MvcForm BeginReportForm(this HtmlHelper helper, string actionName, string controllerName, ReportBaseModel rbm) { RouteValueDictionary routeValues = new RouteValueDictionary(); routeValues.Add("InvType", rbm.InvType); routeValues.Add("CategoryType", rbm.CategoryType); routeValues.Add("DeptType", rbm.DeptType); return(helper.BeginForm(actionName, controllerName, routeValues, FormMethod.Post, new { id = "Report", @class = "form-overflow" })); }
public static MvcForm BeginAjaxValidationForm <TController>(this HtmlHelper htmlHelper, Expression <Action <TController> > action, object htmlAttributes = null) where TController : Controller { RouteValueDictionary attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); attributes["id"] = "AjaxValidationForm"; return(htmlHelper.BeginForm <TController>(action, FormMethod.Post, attributes)); }
public static MvcForm BeginForm <TController>(this HtmlHelper htmlHelper, Expression <Action <TController> > expression, object htmlAttributes) where TController : Controller { var urlParts = UrlProvider <TController> .GetRouteValues(expression); var controller = urlParts["controller"].ToString(); var action = urlParts["action"].ToString(); return(htmlHelper.BeginForm(action, controller, FormMethod.Post, htmlAttributes)); }
/// <summary> /// 扩展 BeginForm 方法,只需要 一个 htmlAttributes 属性参数即可; /// </summary> /// <param name="html"></param> /// <param name="htmlAttributes">普通的对象</param> /// <param name="method"></param> /// <returns></returns> public static MvcForm BeginForm(this HtmlHelper html, object htmlAttributes, FormMethod method = FormMethod.Post) { string actualAction = (string)html.ViewContext.RouteData.Values["action"]; string actualController = (string)html.ViewContext.RouteData.Values["controller"]; var htmlAttributesMap = new RouteValueDictionary(htmlAttributes); var form = html.BeginForm(actualAction, actualController, method, htmlAttributesMap); return(form); }
// When the object is created, write "begin" function public MainFormHelper(HtmlHelper htmlHelper) { object route; if (System.Web.HttpContext.Current.Request.QueryString["modal"] == "1" && System.Web.HttpContext.Current.Request.QueryString["closeonsave"] == "1") route = (object) new {modal = "1", closeonsave = "1"}; else route = System.Web.HttpContext.Current.Request.QueryString["modal"] == "1" ? (object) new {modal = "1"} : (object) new {}; _form = htmlHelper.BeginForm(null, null, route, FormMethod.Post, new { id = "mainForm" } ); var inputBuilder = new TagBuilder("input"); inputBuilder.Attributes.Add("type", "hidden"); inputBuilder.Attributes.Add("id", "UrlHash"); inputBuilder.Attributes.Add("name", "UrlHash"); var modelEdit = htmlHelper.ViewData.Model as ViewModelBase; inputBuilder.Attributes.Add("value", modelEdit != null ? modelEdit.UrlHash : ""); htmlHelper.ViewContext.Writer.Write(inputBuilder); }