本文整理汇总了C#中FormMethod类的典型用法代码示例。如果您正苦于以下问题:C# FormMethod类的具体用法?C# FormMethod怎么用?C# FormMethod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FormMethod类属于命名空间,在下文中一共展示了FormMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderForm
/// <summary>
/// This renders out the form for us
/// </summary>
/// <param name="htmlHelper"></param>
/// <param name="formAction"></param>
/// <param name="method"></param>
/// <param name="htmlAttributes"></param>
/// <param name="surfaceController"></param>
/// <param name="surfaceAction"></param>
/// <param name="area"></param>
/// <param name="additionalRouteVals"></param>
/// <returns></returns>
/// <remarks>
/// This code is pretty much the same as the underlying MVC code that writes out the form
/// </remarks>
private static MvcForm RenderForm(this IHtmlHelper htmlHelper,
string formAction,
FormMethod method,
IDictionary<string, object> htmlAttributes,
string surfaceController,
string surfaceAction,
string area,
object additionalRouteVals = null)
{
if (htmlAttributes == null)
{
htmlAttributes = new Dictionary<string, object>();
}
//ensure that the multipart/form-data is added to the html attributes
if (htmlAttributes.ContainsKey("enctype") == false)
{
htmlAttributes.Add("enctype", "multipart/form-data");
}
var tagBuilder = new TagBuilder("form");
tagBuilder.MergeAttributes(htmlAttributes);
// action is implicitly generated, so htmlAttributes take precedence.
tagBuilder.MergeAttribute("action", formAction);
// method is an explicit parameter, so it takes precedence over the htmlAttributes.
tagBuilder.MergeAttribute("method", HtmlHelper.GetFormMethodString(method), true);
tagBuilder.TagRenderMode = TagRenderMode.StartTag;
tagBuilder.WriteTo(htmlHelper.ViewContext.Writer, new HtmlEncoder());
//new UmbracoForm:
var theForm = new UmbracoForm(htmlHelper.UrlEncoder, htmlHelper.ViewContext, surfaceController, surfaceAction, area, additionalRouteVals);
return theForm;
}
示例2: Form
public Form(ActionResult result)
: base(null)
{
this._result = result;
this._formMethod = System.Web.Mvc.FormMethod.Post;
_actionTypePassed = ActionTypePassed.HtmlActionResult;
}
示例3: jQueryForm
public jQueryForm(ViewContext context, string action, FormMethod method, jQueryAjaxOptions ajaxOptions, IDictionary<string, object> htmlAttributes)
: base("form", TagRenderMode.StartTag)
{
MergeAttributes(htmlAttributes);
Method = method;
Action = action;
ViewContext = context;
OriginalFormContext = context.FormContext;
context.FormContext = new FormContext();
AjaxOptions = ajaxOptions ?? new jQueryAjaxOptions();
if (AjaxOptions != null && AjaxOptions.Metadata)
{
AddClass("jquery-ajax-form");
Attributes.Merge("data-jquery-ajax", AjaxOptions.ToJson());
}
if (string.IsNullOrWhiteSpace(Id))
{
Attributes.Merge("id", string.Format("form{0}", DateTime.UtcNow.Ticks));
}
//context.Writer.Write(f.Html(context));
}
示例4: BeginRouteForm
/// <summary>
/// Writes an opening form tag to the response. When the user submits the form,
/// the request will be processed by the route target.
/// </summary>
/// <param name="htmlHelper">The HTML helper.</param>
/// <param name="routeName">The name of the route to use to obtain the form-post URL.</param>
/// <param name="method">The HTTP method for processing the form, either GET or POST.</param>
/// <param name="routeValues">An object that contains the parameters for evaluatedValueString route.</param>
/// <param name="htmlAttributes">The HTTP method for processing the form, either GET or POST.</param>
/// <returns>An opening form tag.</returns>
public static IDisposable BeginRouteForm(this HtmlHelper htmlHelper, string routeName, FormMethod method = FormMethod.Post, object routeValues = null, object htmlAttributes = null)
{
var routeDictionary = htmlHelper.AutomaticRouteValuesDictionary(routeValues);
var attrDictionary = htmlHelper.AutomaticHtmlAttributes(htmlAttributes);
return BootstrapHelperConfiguration.HtmlRenderer.BeginRouteForm(htmlHelper, routeName, method, routeDictionary, attrDictionary);
}
示例5: With
/// <summary>
/// Sets configuration values for the rendered HTML form.
/// </summary>
/// <param name="actionName">The name of the target action.</param>
/// <param name="controllerName">The name of the target controller.</param>
/// <param name="routeValues">The route values for the target action.</param>
/// <param name="formMethod">The method used to submit the form.</param>
/// <param name="cssClass">The element class.</param>
/// <param name="cssStyle">The element style.</param>
/// <returns>The configured <see cref="System.Web.Mvc.Html.MvcForm"/> instance.</returns>
public MvcForm With(
string actionName = null,
string controllerName = null,
object routeValues = null,
FormMethod formMethod = FormMethod.Post,
string cssClass = null,
string cssStyle = null)
{
base.With(cssClass, cssStyle);
if (controllerName.IsNullOrEmpty())
{
controllerName = this.HtmlHelper.InnerHelper.ViewContext.RouteData.Values["Controller"] as string;
}
if (actionName.IsNullOrEmpty())
{
actionName = this.HtmlHelper.InnerHelper.ViewContext.RouteData.Values["Action"] as string;
}
var htmlAttributes = this.HtmlAttributes;
var safeRouteValues = new RouteValueDictionary(routeValues);
MvcForm form;
form = this.HtmlHelper
.InnerHelper
.BeginForm(actionName, controllerName, safeRouteValues, formMethod, htmlAttributes);
return form;
}
示例6: FormRoute
public static IDisposable FormRoute(this HtmlHelper html, string routeName, FormMethod method, RouteValueDictionary valuesDictionary) {
VirtualPathData virtualPath = RouteTable.Routes.GetVirtualPath(html.ViewContext, routeName, valuesDictionary);
string formAction = (virtualPath == null) ? null : virtualPath.VirtualPath;
SimpleForm form = new SimpleForm(html.ViewContext.HttpContext, formAction, method, null);
form.WriteStartTag();
return form;
}
示例7: Form
/// <summary>
/// Sets action attribute to a form element by using controller and an action method
/// </summary>
/// <param name="action"></param>
/// <param name="controller"></param>
public Form(string action, string controller)
: base(null)
{
this._action = action;
this._controller = controller;
this._formMethod = System.Web.Mvc.FormMethod.Post;
}
示例8: FormContainer
public FormContainer(HtmlTextWriter htmlTextWriter,
string url ,
BootstrapFormType formType = BootstrapFormType.Horizontal,
FormMethod method = FormMethod.Post,
object htmlAttributes = null)
{
this.textWriter = htmlTextWriter;
this.formType = formType;
// textWriter.AddAttribute("method", method.ToString());
//textWriter.AddAttribute("action", url ) ;
var htmlAttributesCollection = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
switch (this.formType)
{
case BootstrapFormType.Horizontal: htmlAttributesCollection.Merge("class", "form-horizontal"); break;
case BootstrapFormType.Vertical: htmlAttributesCollection.Merge("class", "form-vertical"); break;
case BootstrapFormType.Inline: htmlAttributesCollection.Merge("class", "form-inline"); break;
}
foreach (var htmlAttribute in htmlAttributesCollection)
{
textWriter.AddAttribute(htmlAttribute.Key, htmlAttribute.Value.ToString());
}
textWriter.RenderBeginTag(HtmlTextWriterTag.Form);
}
示例9: Form
public Form(Task<ActionResult> taskResult)
: base(null)
{
this._taskResult = taskResult;
this._formMethod = System.Web.Mvc.FormMethod.Post;
_actionTypePassed = ActionTypePassed.HtmlTaskResult;
}
示例10: BeginForm
public static MvcForm BeginForm( this HtmlHelper htmlHelper,
String actionName,
String controllerName,
FormMethod method,
Hash htmlAttributes )
{
return htmlHelper.BeginForm(actionName, controllerName, method, HashHelper.ToStringKeyDictinary( htmlAttributes ));
}
示例11: Init
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());
}
示例12: CarcassBeginForm
/// <summary>
/// Writes an opening <form> tag to the response. When the user submits the form,
/// the request will be processed by an action method.
/// </summary>
/// <param name="htmlHelper">The HTML helper instance that this method extends.</param>
/// <param name="formClass">CSS class for <c>form</c> element</param>
/// <param name="method">The HTTP method for processing the form, either GET or POST.</param>
/// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param>
/// <returns>An opening <form> tag</returns>
public static CarcassMvcForm CarcassBeginForm(this HtmlHelper htmlHelper,
string formClass = CarcassMvcSettings.BootsrapFormClassHorisontal,
FormMethod method = FormMethod.Post,
object htmlAttributes = null)
{
var rawUrl = htmlHelper.ViewContext.HttpContext.Request.RawUrl;
return CarcassBeginFormImpl(htmlHelper, rawUrl, formClass, method, (IDictionary<string, object>)HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
}
示例13: BeginForm
public static MvcForm BeginForm(
[NotNull] this IHtmlHelper htmlHelper,
FormMethod method,
object htmlAttributes)
{
return htmlHelper.BeginForm(actionName: null, controllerName: null, routeValues: null,
method: method, htmlAttributes: htmlAttributes);
}
示例14: Button
public static MvcHtmlString Button(this HtmlHelper helper,
string text, string urlAction, FormMethod method, object htmlAttributes)
{
var tagBuilder = new TagBuilder("input");
FillWithAttributes(tagBuilder, new { type = "submit", formaction = urlAction, formmethod = method.ToString(), value = text });
FillWithAttributes(tagBuilder, htmlAttributes);
return new MvcHtmlString(tagBuilder.ToString());
}
示例15: BeginAngularForm
public static MsAspMvc.MvcForm BeginAngularForm(this HtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method, object htmlAttributes)
{
RouteValueDictionary routeValues = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
if (!routeValues.ContainsKey("name"))
routeValues.Add("name", "form");
htmlHelper.ViewData.Add("formName", routeValues["name"]);
return MsAspMvc.FormExtensions.BeginForm(htmlHelper, actionName, controllerName, method, routeValues);
}