1

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Yes, I would not do this - just one small bit of the website we're maintaining does it, so I'm leaving it like that for now.
0

Could you just call ActionLink in the controller and add the result top your string -

viewModel.Message = "blah blah " + Html.ActionLink("","","") + " blah"; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.