zoukankan      html  css  js  c++  java
  • HtmlHelper扩展之mvchtmlstring

    后台:

    using System;
    using System.Web;
    using System.Web.Mvc;

    namespace EwayFramework.Utils.Token
    {
    public static class HtmlTokenHelper
    {
    public static MvcHtmlString GenerateVerficationToken(this HtmlHelper htmlhelper)
    {
    string formValue = SessionPageTokenView.Encrypt(HttpContext.Current.Session.SessionID + DateTime.Now.Ticks.ToString());
    string sessionname = HttpContext.Current.Request.Path + HttpContext.Current.Request.Params["ID"];
    HttpContext.Current.Session[sessionname] = formValue;
    string fieldName = PageTokenViewBase.HiddenTokenName;
    TagBuilder builder = new TagBuilder("input");
    builder.Attributes["type"] = "hidden";
    builder.Attributes["name"] = fieldName;
    builder.Attributes["value"] = formValue;
    return new MvcHtmlString(builder.ToString(TagRenderMode.SelfClosing));
    }
    }
    }

    前台调用:

    @using EwayFramework.Utils.Token

    @html.GenerateVerficationToken()

    结果:

    会自动生成隐藏控件

  • 相关阅读:
    Django-url反向解析和命名空间
    django-分页paginator
    python-命令模式
    python-访问者模式
    python-责任链模式
    python-备忘录模式
    最长无重复字串
    计算机网络常见面试题
    C++对象模型
    原码反码补码(转)
  • 原文地址:https://www.cnblogs.com/Wtomato/p/7477291.html
Copyright © 2011-2022 走看看