zoukankan
html css js c++ java
好方法,让前台绑定更简单
方法代码
using
System;
using
System.Collections.Generic;
using
System.Text;
namespace
WebHelper.Data
{
public
class
Binds
{
/**/
///
<summary>
///
用于链接中的数据绑定,调用方法:WebHelper.Data.Binds.Eval("http://{0}",Eval("name"));
///
</summary>
public
static
string
Eval(
string
Format,
params
object
[] Args)
{
return
Eval(Format,
true
, Args);
}
/**/
///
<summary>
///
用于链接中的数据绑定
///
</summary>
public
static
string
Eval(
string
Format,
bool
EncodeUrl,
params
object
[] Args)
{
List
<
string
>
args
=
new
List
<
string
>
();
foreach
(
object
arg
in
Args)
{
if
(arg
==
null
)
args.Add(
string
.Empty);
else
args.Add(arg.ToString());
}
if
(EncodeUrl)
return
Url.Encode.EncodeUrl(
string
.Format(Format, args.ToArray()));
else
return
string
.Format(Format, args.ToArray());
}
}
}
用到了另一个类,这是处理中文的
using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.Web;
using
System.Net;
using
System.Text.RegularExpressions;
namespace
WebHelper.Url
{
public
class
Encode
{
public
static
string
EncodeUrl(
string
oldUrl)
{
string
newUrl
=
EncodeGuid(oldUrl);
newUrl
=
EncodeGBcode(newUrl);
return
newUrl;
}
/**/
///
<summary>
///
去掉参数中Guid中的"-"不安全的,必须是正确的Url格式
///
</summary>
///
<param name="oldUrl"></param>
///
<returns></returns>
public
static
string
EncodeGuid(
string
oldUrl)
{
string
newUrl
=
oldUrl;
MatchCollection mc;
Regex r
=
new
Regex(
@"
\w{8}-\w{4}-\w{4}-\w{4}-\w{12}
"
);
//
定义一个Regex对象实例=&
if
(oldUrl.IndexOf(
"
?
"
)
>
0
)
{
mc
=
r.Matches(oldUrl, oldUrl.IndexOf(
'
?
'
));
foreach
(Match match
in
mc)
{
newUrl
=
oldUrl.Replace(match.Value, match.Value.Replace(
"
-
"
,
""
));
}
}
return
newUrl;
}
/**/
///
<summary>
///
编码Url中的中文
///
</summary>
///
<param name="oldUrl"></param>
///
<returns></returns>
public
static
string
EncodeGBcode(
string
oldUrl)
{
string
newUrl
=
System.Web.HttpContext.Current.Server.UrlEncode(oldUrl);
string
strSpecial
=
"
!\
"
#$
%&
'
()*+,/:;<=>?@[\\]^`{|}~% ";
foreach
(
char
tmp
in
strSpecial)
{
newUrl
=
newUrl.Replace(System.Web.HttpContext.Current.Server.UrlEncode(tmp.ToString()), tmp.ToString());
}
return
newUrl;
}
}
}
调用很简单
<
a
href
='<%#
WebHelper.Data.Binds.Eval("http://{0}/Msg.aspx?ID
={1}",Eval("Domain"),Eval("ID"))
%
>
' target="_blank">
<%
#
Eval
(
"
Title
"
)
%>
</
a
>
有了这个方法,调用就很简单了,而且对中文处理也有了
查看全文
相关阅读:
小程序 短信验证码 倒计时 变量作用域
File syncing and sharing software with file encryption and group sharing, emphasis on reliability and high performance.
图片合并与截断
宽度分离
无宽度准则
linux系统/var/log目录下的信息详解
Connection Phase Packets
select version();desc mysql.user;
mysql user password plugin
Please read "Security" section of the manual to find out how to run mysqld as root!
原文地址:https://www.cnblogs.com/yamajia/p/908658.html
最新文章
Running several name-based web sites on a single IP address.
ZeroMQ Distributed Messaging
基于Netty自研网关中间件
如何实现微服务架构中的服务发现?
Chef vs Puppet vs Ansible vs Saltstack: Which Works Best For You?
网站用户访问速度监测分析项目,秒掉基调
ansible
生命周期钩子
Redux
解读 JavaScript 之引擎、运行时和堆栈调用
热门文章
Vue 单页面应用 SEO SPA single page application advantages and disadvantages
把渲染和逻辑分离
if UDP is permitted
括号序列 是否是 合法的
Conditions in bash scripting (if statements)
寻找JAVA_HOME find java
flume-ng script should first try finding java from PATH and then try using bigtop, instead of vice-versa
JS中的hook机制
Maximum Memory and CPU Limitations for Linux Server
上拉加载 下拉刷新
Copyright © 2011-2022 走看看