在我的一个控制器动作,我生成一些XML。该XML中的一个属性是对另一个控制器和操作的href,带有一些参数。 XML应该看起来像这样:
<projects> <project id="42" name="Project X",href="/projects/42"/> <!-- etc. --> </projects>
我不介意如果URL是相对的或绝对的,但我的问题是这样:我如何生成控制器代码中的URL,以类型安全的方式?
换句话说,我如何做什么HtmlHelper.ActionLink,但从控制器?
解决方法
发现它通过使用反射器:
string href = Url.Action("DetailsAsXml",new { projectId = item.Id });
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。