user974685
user974685

Reputation: 23

Passing string containing an Html.ActionLink to a view from a controller

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

to get it to display correctly, with no luck - any ideas?

Upvotes: 1

Views: 339

Answers (2)

ipr101
ipr101

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

David Hedlund
David Hedlund

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

Related Questions