asp.net mvc 4设置viewbag来链接

时间:2014-08-06 07:16:03

标签: asp.net asp.net-mvc-3

我从控制器变量为@ViewBag.confile以查看它是否有效但是我把它放到链接中但是我没有显示但我在链接之外它显示正确。 我想将这个@ViewBag.confile变量添加到href tag我的代码中的错误。我可以在这里实现这个是我的代码

我正在使用asp.net mvc 4

<a href="http://localhost:64049/Content/" @ViewBag.confile >Download Converted File          @ViewBag.confile</a>

@ ViewBag.confile变量在视图中正确显示但问题是当我点击链接时我做HTTP Error 403.14 - Forbidden error网页浏览器地址栏仅显示http://localhost:64049/Content/ @ViewBag.confile变量缺失

2 个答案:

答案 0 :(得分:3)

这将有效:

<a href="http://localhost:64049/Content/@(ViewBag.confile)">Download Converted File @(ViewBag.confile)</a>

答案 1 :(得分:1)

您应该使用tilda语法来允许MVC解析引用:

<a href="~/Content/@( ViewBag.confile )">Download Converted File @ViewBag.confile</a>
相关问题