@Html.ActionLink2SD 怎么...

当前位置: →
→ Mvc扩展Html.ActionLink强类型扩展
Mvc扩展Html.ActionLink强类型扩展
& 作者及来源: 香草柠檬 - 博客园 &
&收藏到→_→:
摘要: Mvc扩展Html.ActionLink(强类型扩展)
"Mvc扩展Html.ActionLink强类型扩展"::
在网上看了有说把actionlink扩展成类似于@html.actionlink&t&(t=&t.index(...))这种写法的,但是按照他们的代码写都没有试成功,于是就自己写了一个,但是只支持
@{html.actionlink&t&(t=&t.index(...));}这种写法,因为@html.actionlink&t&(t=&t.index(...))这种写法会报错,具体是什么原因也不清楚。
代码写的不是很好,仅供参考:
&&& public static void actionlink&t&(this htmlhelper helper, expression&action&t&& action, string linkname, dynamic para) where t : class&&&&&&& {&&&&&&&&&&& string lamda = action.tostring();&&&&&&&&&&& string lamexp = lamda.substring(lamda.indexof('.') + 1);&&&&&&&&&&& string action = lamexp.substring(0, lamexp.indexof('('));&&&&&&&&&&& string controller = helper.viewcontext.routedata.values["controller"].tostring();&&&&&&&&&&& stringbuilder builder = new stringbuilder();
&&&&&&&&&&& builder.appendformat("&a& href='/{0}/{1}", controller, action);&&&&&&&&&&& if (para != null)&&&&&&&&&&& {&&&&&&&&&&&&&&& var props = para.gettype().getproperties();&&&&&&&&&&&&&&& builder.append("?");&&&&&&&&&&&&&&& foreach (var item in props)&&&&&&&&&&&&&&& {&&&&&&&&&&&&&&&&&&& string paraname = item.&&&&&&&&&&&&&&&&&&& object paraval = item.getvalue(para, null);&&&&&&&&&&&&&&&&&&& builder.appendformat("{0}={1}", paraname, paraval);&&&&&&&&&&&&&&&&&&& builder.append("&");&&&&&&&&&&&&&&& }&&&&&&&&&&&&&&& builder.remove(builder.length - 1, 1);&&&&&&&&&&& }&&&&&&&&&&& builder.append("'&");&&&&&&&&&&& builder.append(linkname);&&&&&&&&&&& builder.append("&/a&");&&&&&&&&&&& httpcontext.current.response.write(builder.tostring());&&&&&&& }
如果谁有更好的办法可以留言一下,谢谢!搜索此文相关文章:扩展此文来自: 马开东博客
网址: 站长QQ
Mvc扩展Html.ActionLink强类型扩展_博客园相关文章
博客园_总排行榜
博客园_最新
博客园_月排行榜
博客园_周排行榜
博客园_日排行榜

参考资料

 

随机推荐