2023-02-17 385
我非常困惑为什么这个代码
Html.ActionLink("About", "About", "Home", new { hidefocus = "hidefocus" })
结果在此链接中:
<a hidefocus="hidefocus" href="/Home/About?Length=4">About</a>
hidefocus部分是我旨在实现的目标,但?Length=4来自哪里?
长度= 4来自尝试序列化字符串对象.您的代码正在运行此ActionLink方法:
public static string ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues, object htmlAttributes)
这需要一个string对象”home”,用于rutevalues,MVC管道搜索的公共属性将它们转换为路由值.在string对象的情况下,唯一的公共属性是Length,因为没有使用长度参数定义的路由,它将属性名称和值附加为查询字符串参数.如果您从不在HomeController的页面上运行此操作,您可能会发现它将丢失有关丢失About操作方法的错误.尝试使用以下内容:
Html.ActionLink("About", "About", new { controller = "Home" }, new { hidefocus = "hidefocus" })
我解决的方式是在匿名声明(new {})之前将null添加到第四个参数,以便它使用以下方法过载:( linktext,actionname,controllerrername,routevalues,htmlattributes):
Html.ActionLink("About", "About", "Home", null, new { hidefocus = "hidefocus" })
您忘记添加htmlattributes parm.
这将在没有任何变化的情况下工作:
Html.ActionLink("About", "About", "Home", new { hidefocus = "hidefocus" },null)
以上所述是小编给大家介绍的为什么Html.ActionLink呈现"?Length=4",希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对77isp云服务器技术网的支持!
原文链接:https://77isp.com/post/34217.html
=========================================
https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。
数据库技术 2022-03-28
网站技术 2022-11-26
网站技术 2023-01-07
网站技术 2022-11-17
Windows相关 2022-02-23
网站技术 2023-01-14
Windows相关 2022-02-16
Windows相关 2022-02-16
Linux相关 2022-02-27
数据库技术 2022-02-20
抠敌 2023年10月23日
嚼餐 2023年10月23日
男忌 2023年10月22日
瓮仆 2023年10月22日
簿偌 2023年10月22日
扫码二维码
获取最新动态