0

I have an MVC Razor view that pulls change log information from a database (a table which only I have access to, limiting security concerns).

<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Description)
        </th>
    </tr>

    @foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Description)
            </td>
        </tr>
    }
</table>

The description will contain values like New page available: http://localhost:0000/app/NewItem. What I'm trying to figure out is how to make that web address active.

I.e., turn New page available: http://localhost:0000/app/NewItem

into: New page available: http://localhost:0000/app/NewItem

and have the link properly rendered on the page. Is there a simple way to accomplish this, short of using regular expressions in the controller to pull that link out?

Dan Champagne
  • 890
  • 2
  • 17
  • 37
  • 3
    First, I'd consider storing the link as a separate property. Then make a [custom template](http://stackoverflow.com/questions/5710140/how-do-i-create-a-mvc-razor-template-for-displayfor) for the property that will output your description with the link wrapped in an anchor. – Jasen Feb 29 '16 at 18:49
  • That's going to be my fall back if there isn't an easier way to do it. – Dan Champagne Feb 29 '16 at 18:54
  • 1
    I don't know the details of your application. But seems to me that is the easiest and most maintainable way to do this. You could also encode that link with html in the description when you first create the description. – Jasen Feb 29 '16 at 19:07
  • Is it possible to store the data like this? `New page available: [http://localhost:0000/app/NewItem](http://localhost:0000/app/NewItem)`? You could then use a markdown tool to render the data as HTML. – danludwig Feb 29 '16 at 19:18
  • Check this: http://stackoverflow.com/a/19221240/7720 – Romias Feb 29 '16 at 20:44
  • http://stackoverflow.com/questions/37684/how-to-replace-plain-urls-with-links – JamieD77 Feb 29 '16 at 20:58

0 Answers0