Reputation: 23
In my controller I have a string containing C#, something like
viewModel.Message = 'blah blah <%=Html.ActionLink("","","")%> blah';
and in the corresponding view I have tried
Model.Message
@Html.Raw(Model.Message)
to get it to display correctly, with no luck - any ideas?
Upvotes: 1
Views: 339
Reputation: 24226
Could you just call ActionLink
in the controller and add the result top your string -
viewModel.Message = "blah blah " + Html.ActionLink("","","") + " blah";
Upvotes: 0
Reputation: 129782
You'd have to create an instance of HtmlHelper
in your controller for that, and have your message set to
viewModel.Message = "blah blah" + htmlHelper.ActionLink("","","") + " blah";
But do you really want your controller to be concerned with things like rendering HTML links? If you cannot delegate the task to the View entirely, how about just setting a Url property? You are able to access Url.Action("","")
from your controller.
Upvotes: 1