示例#1
0
        protected string RenderHtmlElements()
        {
            StringBuilder formHtml = new StringBuilder();

            if (!_fapColumns.Any())
            {
                return("未发现元数据");
            }
            formHtml.AppendLine("<form class=\"form-horizontal\" method=\"post\" id=\"##formid##\" role=\"form\">");
            formHtml.AppendLine(RenderBaseControl());
            formHtml.AppendLine(RenderFormContent());
            //formToken 用于防止重复提交
            string avoidRepeatToken = UUIDUtils.Fid;

            formHtml.AppendLine(CreateHiddenControl(FapWebConstants.AVOID_REPEAT_TOKEN, avoidRepeatToken));
            //XSRF/CSRF 防护
            IAntiforgery antiforgery    = ActivatorUtilities.GetServiceOrCreateInstance <IAntiforgery>(_serviceProvider);
            var          context        = _serviceProvider.GetService <IHttpContextAccessor>();
            IHtmlContent antiforeryHtml = antiforgery.GetHtml(context.HttpContext);
            var          writer         = new System.IO.StringWriter();

            antiforeryHtml.WriteTo(writer, HtmlEncoder.Default);
            formHtml.AppendLine(writer.ToString());
            //放验证信息
            formHtml.AppendLine("<div class=\"error\">				</div>");
            formHtml.AppendLine("</form>");
            formHtml.AppendLine("<div class=\"row\">");
            formHtml.AppendLine("<div class=\"col-xs-12 col-sm-6\" id=\"frm-result\"></div>");
            formHtml.AppendLine("</div>");
            formHtml.Replace("##formid##", $"frm-{FormId}");

            return(formHtml.ToString());
        }
        protected override void GenerateEndForm()
        {
            // Always output an anti-forgery token
            IAntiforgery antiforgery     = _viewContext.HttpContext.RequestServices.GetRequiredService <IAntiforgery>();
            IHtmlContent antiforgeryHtml = antiforgery.GetHtml(_viewContext.HttpContext);

            _viewContext.Writer.Write(antiforgeryHtml.ToHtmlString());

            // write out the hidden surface form routes
            _viewContext.Writer.Write(_surfaceControllerInput);

            base.GenerateEndForm();
        }