当前位置: 首页>>代码示例>>C#>>正文


C# FormMethod.ToString方法代码示例

本文整理汇总了C#中FormMethod.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# FormMethod.ToString方法的具体用法?C# FormMethod.ToString怎么用?C# FormMethod.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FormMethod的用法示例。


在下文中一共展示了FormMethod.ToString方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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);
            
        }
开发者ID:AbdoNile,项目名称:Foundation.Old,代码行数:28,代码来源:FormContainer.cs

示例2: 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());
        }
开发者ID:tEkaterina,项目名称:photoalbum,代码行数:9,代码来源:HtmlExtension.cs

示例3: BeginRouteFormWithRouteNameMethodAndHtmlAttributesParameters_CallsHtmlGeneratorWithExpectedValues

        public void BeginRouteFormWithRouteNameMethodAndHtmlAttributesParameters_CallsHtmlGeneratorWithExpectedValues(
            string routeName,
            FormMethod method,
            object htmlAttributes)
        {
            // Arrange
            var tagBuilder = new TagBuilder(tagName: "form");
            var htmlGenerator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
            var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(htmlGenerator.Object);
            htmlGenerator
                .Setup(g => g.GenerateRouteForm(
                    htmlHelper.ViewContext,
                    routeName,
                    null,   // routeValues
                    method.ToString().ToLowerInvariant(),
                    htmlAttributes))
                .Returns(tagBuilder)
                .Verifiable();

            if (method != FormMethod.Get)
            {
                htmlGenerator
                    .Setup(g => g.GenerateAntiforgery(htmlHelper.ViewContext))
                    .Returns(HtmlString.Empty)
                    .Verifiable();
            }

            // Guards
            Assert.NotNull(htmlHelper.ViewContext);
            var writer = Assert.IsAssignableFrom<StringWriter>(htmlHelper.ViewContext.Writer);
            var builder = writer.GetStringBuilder();
            Assert.NotNull(builder);

            // Act
            var mvcForm = htmlHelper.BeginRouteForm(routeName, method, htmlAttributes);

            // Assert
            Assert.NotNull(mvcForm);
            Assert.Equal("<form>", builder.ToString());
            htmlGenerator.Verify();
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:41,代码来源:HtmlHelperFormExtensionsTest.cs

示例4: TagBuilder

        public void BeginFormWithMethodAndHtmlAttributesParameters_SuppressAntiforgery_CallsHtmlGeneratorWithExpectedValues(
            FormMethod method,
            object htmlAttributes)
        {
            // Arrange
            var tagBuilder = new TagBuilder(tagName: "form");
            var htmlGenerator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
            var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(htmlGenerator.Object);
            htmlGenerator
                .Setup(g => g.GenerateForm(
                    htmlHelper.ViewContext,
                    null,   // actionName
                    null,   // controllerName
                    null,   // routeValues
                    method.ToString().ToLowerInvariant(),
                    htmlAttributes))
                .Returns(tagBuilder)
                .Verifiable();

            // Guards
            Assert.NotNull(htmlHelper.ViewContext);
            var writer = Assert.IsAssignableFrom<StringWriter>(htmlHelper.ViewContext.Writer);
            var builder = writer.GetStringBuilder();
            Assert.NotNull(builder);

            // Act
            var mvcForm = htmlHelper.BeginForm(method, antiforgery: false, htmlAttributes: htmlAttributes);

            // Assert
            Assert.NotNull(mvcForm);
            Assert.Equal("<form>", builder.ToString());
            htmlGenerator.Verify();
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:33,代码来源:HtmlHelperFormExtensionsTest.cs

示例5: ProcessAsync_GeneratesAntiforgeryCorrectly

        public async Task ProcessAsync_GeneratesAntiforgeryCorrectly(
            bool? antiforgery,
            FormMethod method,
            string expectedPostContent)
        {
            // Arrange
            var viewContext = CreateViewContext();
            var expectedAttribute = new TagHelperAttribute("method", method.ToString().ToLowerInvariant());
            var context = new TagHelperContext(
                allAttributes: new TagHelperAttributeList(new[] { expectedAttribute }),
                items: new Dictionary<object, object>(),
                uniqueId: "test");
            var output = new TagHelperOutput(
                "form",
                attributes: new TagHelperAttributeList(),
                getChildContentAsync: (useCachedResult, encoder) =>
                {
                    var tagHelperContent = new DefaultTagHelperContent();
                    tagHelperContent.SetContent("Something");
                    return Task.FromResult<TagHelperContent>(tagHelperContent);
                });
            var generator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
            generator
                .Setup(mock => mock.GenerateForm(
                    It.IsAny<ViewContext>(),
                    It.IsAny<string>(),
                    It.IsAny<string>(),
                    It.IsAny<object>(),
                    It.IsAny<string>(),
                    It.IsAny<object>()))
                .Returns(new TagBuilder("form"));

            generator.Setup(mock => mock.GenerateAntiforgery(viewContext))
                     .Returns(new HtmlString("<input />"));
            var formTagHelper = new FormTagHelper(generator.Object)
            {
                Action = "Index",
                Antiforgery = antiforgery,
                ViewContext = viewContext,
                Method = method.ToString().ToLowerInvariant()
            };

            // Act
            await formTagHelper.ProcessAsync(context, output);

            // Assert
            Assert.Equal("form", output.TagName);
            Assert.Equal(TagMode.StartTagAndEndTag, output.TagMode);
            var attribute = Assert.Single(output.Attributes);
            Assert.Equal(expectedAttribute, attribute);
            Assert.Empty(output.PreContent.GetContent());
            Assert.True(output.Content.GetContent().Length == 0);
            Assert.Equal(expectedPostContent, output.PostContent.GetContent());
        }
开发者ID:xuchrist,项目名称:Mvc,代码行数:54,代码来源:FormTagHelperTest.cs

示例6: BeginRouteForm_RendersExpectedValues

        public void BeginRouteForm_RendersExpectedValues(
            string routeName,
            object routeValues,
            FormMethod method,
            object htmlAttributes)
        {
            // Arrange
            var expectedAction = "http://localhost/Hello/World";
            var expectedStartTag = string.Format(
                "<form action=\"HtmlEncode[[{0}]]\" method=\"HtmlEncode[[{1}]]\"{2}>",
                expectedAction,
                method.ToString().ToLowerInvariant(),
                GetHtmlAttributesAsString(htmlAttributes));

            var urlHelper = new Mock<IUrlHelper>(MockBehavior.Strict);
            urlHelper
                .Setup(realHelper => realHelper.RouteUrl(It.Is<UrlRouteContext>(context =>
                    string.Equals(context.RouteName, routeName) &&
                    context.Values == routeValues &&
                    context.Protocol == null &&
                    context.Host == null &&
                    context.Fragment == null)))
                .Returns(expectedAction)
                .Verifiable();
            var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(urlHelper.Object);

            // Guards
            Assert.NotNull(htmlHelper.ViewContext);
            var writer = Assert.IsAssignableFrom<StringWriter>(htmlHelper.ViewContext.Writer);
            var builder = writer.GetStringBuilder();
            Assert.NotNull(builder);

            // Act
            var mvcForm = htmlHelper.BeginRouteForm(routeName, routeValues, method, htmlAttributes);

            // Assert
            Assert.NotNull(mvcForm);
            Assert.Equal(expectedStartTag, builder.ToString());
            urlHelper.Verify();
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:40,代码来源:HtmlHelperFormTest.cs

示例7: BeginRouteFormWithRouteNameRouteValuesAndMethodParameters_CallsHtmlGeneratorWithExpectedValues

        public void BeginRouteFormWithRouteNameRouteValuesAndMethodParameters_CallsHtmlGeneratorWithExpectedValues(
            string routeName,
            object routeValues,
            FormMethod method)
        {
            // Arrange
            var tagBuilder = new TagBuilder(tagName: "form", htmlEncoder: new NullTestEncoder());
            var htmlGenerator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
            var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(htmlGenerator.Object);
            htmlGenerator
                .Setup(realHelper => realHelper.GenerateRouteForm(
                    htmlHelper.ViewContext,
                    routeName,
                    routeValues,
                    method.ToString().ToLowerInvariant(),
                    null))  // htmlAttributes
                .Returns(tagBuilder)
                .Verifiable();

            // Guards
            Assert.NotNull(htmlHelper.ViewContext);
            var writer = Assert.IsAssignableFrom<StringWriter>(htmlHelper.ViewContext.Writer);
            var builder = writer.GetStringBuilder();
            Assert.NotNull(builder);

            // Act
            var mvcForm = htmlHelper.BeginRouteForm(routeName, routeValues, method);

            // Assert
            Assert.NotNull(mvcForm);
            Assert.Equal("<form>", builder.ToString());
            htmlGenerator.Verify();
        }
开发者ID:RehanSaeed,项目名称:Mvc,代码行数:33,代码来源:HtmlHelperFormExtensionsTest.cs

示例8: TagBuilder

        public void BeginFormWithActionNameContollerNameRouteValuesAndMethodParameters_CallsHtmlGeneratorWithExpectedValues(
            string actionName,
            string controllerName,
            object routeValues,
            FormMethod method)
        {
            // Arrange
            var tagBuilder = new TagBuilder(tagName: "form");
            var htmlGenerator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
            var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(htmlGenerator.Object);
            htmlGenerator
                .Setup(g => g.GenerateForm(
                    htmlHelper.ViewContext,
                    actionName,
                    controllerName,
                    routeValues,
                    method.ToString().ToLowerInvariant(),
                    null))  // htmlAttributes
                .Returns(tagBuilder)
                .Verifiable();
            htmlGenerator
                .Setup(g => g.GenerateAntiforgery(htmlHelper.ViewContext))
                .Returns(HtmlString.Empty)
                .Verifiable();

            // Guards
            Assert.NotNull(htmlHelper.ViewContext);
            var writer = Assert.IsAssignableFrom<StringWriter>(htmlHelper.ViewContext.Writer);
            var builder = writer.GetStringBuilder();
            Assert.NotNull(builder);

            // Act
            var mvcForm = htmlHelper.BeginForm(actionName, controllerName, routeValues, method);

            // Assert
            Assert.NotNull(mvcForm);
            Assert.Equal("<form>", builder.ToString());
            htmlGenerator.Verify();
        }
开发者ID:phinq19,项目名称:git_example,代码行数:39,代码来源:HtmlHelperFormExtensionsTest.cs

示例9: PackFormMethod

 public static String PackFormMethod(FormMethod formMethod)
 {
     return "method=\"" + formMethod.ToString() + "\"";
 }
开发者ID:zformular,项目名称:ValueHelper,代码行数:4,代码来源:TagHelper.cs


注:本文中的FormMethod.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。