Asp.net mvc 字符串html帮助器参数中的Razor变量

Asp.net mvc 字符串html帮助器参数中的Razor变量,asp.net-mvc,razor,Asp.net Mvc,Razor,以下是may Html helper: @Html.ActionLink("CONTACT THE USER ABOUT THIS LISTING", "create", "contactform", new { recipientID = Model.User.Id, productid = Model.Product.ID }, null) 我想做的是: @Html.ActionLink("CONTACT " Model.UserName " ABOUT THIS LISTING",

以下是may Html helper:

 @Html.ActionLink("CONTACT THE USER ABOUT THIS LISTING", "create", "contactform", new { recipientID = Model.User.Id, productid = Model.Product.ID }, null)
我想做的是:

 @Html.ActionLink("CONTACT " Model.UserName " ABOUT THIS LISTING", "create", "contactform", new { recipientID = Model.User.Id, productid = Model.Product.ID }, null)

可以这样做吗?

您可以使用
+
运算符来连接C#中的字符串值:

或者类似于
string.Format()
的内容:

string.Format("CONTACT {0} ABOUT THIS LISTING", Model.UserName)

是的,只需使用标准字符串连接

@Html.ActionLink("CONTACT " + Model.UserName + " ABOUT THIS LISTING", "create", "contactform", new { recipientID = Model.User.Id, productid = Model.Product.ID }, null)

非常感谢。我无法得到任何结果,因为在本例中Model.UserName不接受任何值。所以我一直认为我做错了什么。。我真傻。再次感谢。
@Html.ActionLink("CONTACT " + Model.UserName + " ABOUT THIS LISTING", "create", "contactform", new { recipientID = Model.User.Id, productid = Model.Product.ID }, null)
@Html.ActionLink($"CONTACT {Model.UserName} ABOUT THIS LISTING", "create", "contactform", new { recipientID = Model.User.Id, productid = Model.Product.ID }, null)