I'm trying to output a link and link text from a custom model so it is editable in the page editor. It works fine normally but not in the page editor. In my model class i have 2 strings like this:
public string Link { get; set; }
public string LinkText { get; set; }
I try to make the text editable in a repository like this:
model.LinkText = FieldRenderer.Render(item, "Link Text");
model.Link = LinkManager.getItemUrl(item);
in my .cshtml file i am outputting the fields like this:
<a href="@Model.Link>@Model.LinkText<a/>
Am i going about this the wrong way or can i get this code to work with some tweaks ?
To get the editors to work in the page editor, you would need to change the type of your property.
Change
public string Link { get; set; }
to
public IHtmlString Link { get; set; }
That will allow MVC to render the html components of the page editor. That should take care of your link text in the page editor.
To make the link editable would depend on what the field type is.