问题
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