コード例 #1
0
ファイル: SubmitButtonAndLink.cs プロジェクト: evkap/DVS
		public static MvcHtmlString SubmitLink(this HtmlHelper helper, string title, string formId, string actionName, string controllerName, ValidationType validationType = ValidationType.All, object htmlAttributes = null, object submitParams = null)
		{
			var url = GetActionUrl(helper.ViewContext.RequestContext, actionName, controllerName);
			var paramsDictionary = new RouteValueDictionary(submitParams);
			var linkTag = GetSubmitTag("a", title, htmlAttributes);
			linkTag.Attributes.Add("href", "#");

			if (paramsDictionary.Count > 0)
			{
				var key = paramsDictionary.GetHashCode();
				var scriptTag = GetWrapperScriptTag(paramsDictionary, key);
				var script = String.Format("submitFormWithParams_{3}(this, event, '#{0}', '{1}', '{2}'); return false;", formId, url, validationType.ToString(), key);
				linkTag.Attributes.Add("onclick", script);
				return MvcHtmlString.Create(scriptTag.ToString(TagRenderMode.Normal) + linkTag.ToString(TagRenderMode.Normal));
			}
			else
			{
				var script = String.Format("submitFormWithoutParams(this, event, '#{0}', '{1}', '{2}'); return false;", formId, url, validationType.ToString());
				linkTag.Attributes.Add("onclick", script);
				return MvcHtmlString.Create(linkTag.ToString(TagRenderMode.Normal));
			}
		}
コード例 #2
0
ファイル: SubmitButtonAndLink.cs プロジェクト: evkap/DVS
		public static MvcHtmlString SubmitButton(this HtmlHelper helper, string title, string formId, string actionName, string controllerName, ValidationType validationType = ValidationType.All, object htmlAttributes = null, object submitParams = null, bool addIcon = false, bool isIconFirst = true, string iconClass = null, string additionalScript = null, object routeValues = null)
		{
			if (addIcon)
			{
				var devider = !String.IsNullOrWhiteSpace(title) ? " " : string.Empty;
				var iconTemplate = String.Format("<i class='{0}'></i>", iconClass);
				if (isIconFirst)
				{
					title = String.Format("{0}{2}{1}", iconTemplate, title, devider);
				}
				else
				{
					title = String.Format("{0}{2}{1}", title, iconTemplate, devider);
				}
			}

			var url = GetActionUrl(helper.ViewContext.RequestContext, actionName, controllerName, routeValues);
			var paramsDictionary = new RouteValueDictionary(submitParams);
			var buttonTag = GetSubmitTag("button", title, htmlAttributes);
			buttonTag.Attributes.Add("type", "button");

			if (paramsDictionary.Count > 0)
			{
				var key = paramsDictionary.GetHashCode();
				var scriptTag = GetWrapperScriptTag(paramsDictionary, key);
				var script = String.Format("submitFormWithParams_{3}(this, event, '#{0}', '{1}', '{2}');", formId, url, validationType.ToString(), key);
				script = additionalScript == null ? script : String.Format("{0} {1}", additionalScript, script);
				buttonTag.Attributes.Add("onclick", script);
				return MvcHtmlString.Create(scriptTag.ToString(TagRenderMode.Normal) + buttonTag.ToString(TagRenderMode.Normal));
			}
			else
			{
				var script = String.Format("submitFormWithoutParams(this, event, '#{0}', '{1}', '{2}');", formId, url, validationType.ToString());
				script = additionalScript == null ? script : String.Format("{0} {1}", additionalScript, script);
				buttonTag.Attributes.Add("onclick", script);
				return MvcHtmlString.Create(buttonTag.ToString(TagRenderMode.Normal));
			}
		}