字符串html辅助参数

时间:2017-03-31 16:42:56

标签: asp.net-mvc razor

这可能是Html帮手:

 @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)

可以吗?

3 个答案:

答案 0 :(得分:1)

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

"CONTACT " + Model.UserName + " ABOUT THIS LISTING"

或类似string.Format()

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

答案 1 :(得分:0)

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

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

答案 2 :(得分:0)

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