0

I'm having a very hard time figuring out the syntax to correctly handle if the Email is null then display nothing. The phone column works fine for finding and so does '' : 'a' in the ClientTemplate, however, using what I have below I continuously get Uncaught Error: Invalid template:

Any help fixing the syntax would be greatly appreciated.

    @(Html.Kendo().Grid <MVCSite.Model.ProspectSearchContact> ()
        .Name("gridContacts_#=ProspectId#") // template expression, to be evaluated in the master context
        .Columns(columns => {


            columns.Bound(o => o.Id).Width(150).Visible(false);
            columns.Bound(o => o.ContactName).Title("Name").Width(100);
            columns.Bound(o => o.ContactType).Width(150);
            columns.Bound(o => o.Email).ClientTemplate("#= Email == null ? '' : '<a href='mailto:\\#= Email \\#'>\\#= Email \\#</a>'");
            columns.Bound(o => o.Phone).ClientTemplate("<a href='tel:\\#= Phone \\#'>\\#= Phone \\#</a>").Width(150);
        })
        .ToolBar(toolbar => toolbar.Create())
        .DataSource(dataSource => dataSource
          .Ajax()
          .Model(model => {
              model.Id(p => p.Id);
              model.Field(p => p.ProspectId).Editable(false);
          })
          .PageSize(5)
          .Create(update => update.Action("NoteInsert", "DataSource", new {
              ProspectId = "#=ProspectId#"
          }))
          .Read(read => read.Action("ProspectGridItemDataSource", "ProspectingDataSource", new {
              Id = "#=ProspectId#", dataType = "Contact"
          }))
          .Update(update => update.Action("EditingPopup_Update", "Grid"))
          .Destroy(update => update.Action("EditingPopup_Destroy", "Grid"))
        )
        .Pageable()
        .Sortable()
        .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("GridContactEntry"))
        .ToClientTemplate()

1 Answer 1

0

I ended up going with a javascript method. Didn't seem like I had to but I just finally gave in

` columns.Bound(o => o.Email).ClientTemplate("\\#=renderEmail(data)\\#");

columns.Bound(o => o.Phone).ClientTemplate("\\#=renderPhone(data)\\#");

`

function renderEmail(data) {
    if (data.Email) {
        return `<a href="mailto:${data.Email}">${data.Email}</a>`;
    } else {
        return '';
    }
}
function renderPhone(data) {
    if (data.Phone) {
        return `<a href="tel:${data.Phone}">${data.Phone}</a>`;
    } else {
        return '';
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.