2017-03-31 37 views
0

這裏裏面剃刀變量5月的HTML幫助:字符串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) 

能不能做到?

回答

1

可以使用+運營商在C#來連接字符串值:

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

或者類似的東西,而不是string.Format()

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

非常感謝。我無法得到任何結果,因爲在這種情況下Model.UserName沒有任何價值。所以我一直認爲我做錯了什麼。我多麼愚蠢。再次感謝。 – Luke

0

是,只需使用標準的字符串concantenation。

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