Hi I'm really stumped on this one, then again it's one of my first html helpers (that I haven't pinched).
Basically I have an object and a few options which I then want to display a a tag with a few options.
my code so far is
public static IHtmlString DocumentModalLink(this HtmlHelper htmlHelper, CesaDocument doc, string title, string model, string style, string inner)
{
var builder = new TagBuilder("a");
builder.MergeAttribute("title", title);
builder.MergeAttribute("href", "javascript:;");
builder.MergeAttribute("data-toggle", "model");
builder.MergeAttribute("data-target", model);
builder.AddCssClass("btn");
builder.AddCssClass("btn-" + style);
builder.InnerHtml = inner;
builder.MergeAttribute("data-docid", doc.Id.ToString());
builder.MergeAttribute("data-docdate", htmlHelper.DisplayFor(x => doc.DocDate).ToString());
builder.MergeAttribute("data-client", htmlHelper.DisplayFor(x => doc.Surname).ToString() + ", " + htmlHelper.DisplayFor(x => doc.Forename).ToString());
builder.MergeAttribute("data-lastmoddate", htmlHelper.DisplayFor(x => doc.Modified).ToString());
builder.MergeAttribute("data-lastmoduser", htmlHelper.DisplayFor(x => doc.ModifiedBy.Value).ToString());
builder.MergeAttribute("data-docname", htmlHelper.DisplayFor(x => doc.Name).ToString());
builder.MergeAttribute("data-docsection", htmlHelper.DisplayFor(x => doc.SectionLookup.Value).ToString());
builder.MergeAttribute("data-businessunit", htmlHelper.DisplayFor(x => doc.BusinessUnitLookup.Value).ToString());
builder.MergeAttribute("data-doctitle", htmlHelper.DisplayFor(x => doc.DocTitle.Value).ToString());
return MvcHtmlString.Create(builder.ToString());
}
and I can call that using @Html.DocumentModalLink(d, "Notification", "#NotificationsCreateModal","primary", "<span class=\"glyphicon glyphicon-bell\"></span>")
but that doesn't work. The DisplayFor only work for expressions which I don't know how to use successfully.
My true problems are the docDate which I want to format correctly. So basically yeah how to use DisplayFor within a helper for multiple fields.
Thanks