I want to display a text with 2 links inside the text in MVC view! The text link are dynamic from server side and looks like this in controller:
Model.Message = "You have used up all your credits for this month (see your credit balance {FirstLink}). You can buy credits {SecondLink}";
In view I have something like this
@{
var messageToShow = @Model.Message;
var newText = Html.ActionLink(Model.LinkText, Model.LinkAction, Model.LinkController, Model.LinkRouteValues).ToString();
var link = Html.ActionLink(Model.SecondLinkText, Model.SecondLinkAction, Model.SecondLinkController, Model.LinkRouteValues).ToString();
}
@if (!string.IsNullOrEmpty(Model.LinkText))
{
messageToShow = messageToShow.Replace("{FirstLink}", newText);
}
@if (!string.IsNullOrEmpty(Model.SecondLinkText))
{
messageToShow = messageToShow.Replace("{SecondLink}", link);
}[![enter image description here][1]][1]
@Html.Raw(messageToShow)
This is working like it is but I have to add the class to it like this
@Html.ActionLink(Model.SecondLinkText, Model.SecondLinkAction, Model.SecondLinkController, Model.LinkRouteValues, new { @class = "link" })
When adding the ,new{ @class = "link"} I got syntax error since the closing } is badly interpreted by razor engine.
Can you help out or maybe suggest a better solution?
Thanks