How to include an MVC Razor variable within Url.Content?

℡╲_俬逩灬. 提交于 2019-12-23 07:49:37

问题


Using MVC 3 Razor, how can I specify a variable within a call to @Url.Content().

Example:

@{
var myVar = Request.QueryString["foo"];
}

<a href="@Url.Content("~/bar?@myvar")">click here</a>

回答1:


You're already in the c# context at that point, so you can use the variable just like you would in a code file. Try this:

<a href="@Url.Content("~/bar?" + myvar)">click here</a>


来源:https://stackoverflow.com/questions/6066002/how-to-include-an-mvc-razor-variable-within-url-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!