1

Is it possible to use inline HTML inside a @Html.Grid (I'm trying to create a hyperlink tag in one of the columns). Here is an example:

@model Example.Models.ExampleItems

@{
    ViewBag.Title = "Example Items";
}

<div id="ExampleContentInnerContainer">
<h2>Example Items</h2>

<div id="ExampleListGrid">
    <span class="ExampleGrid">
    <p>
        @Html.Grid(Model.ExampleList).Columns(c =>
        {
            c.For(a => a.Example.Mandatory == true ? "Yes" : "No").Named("Mandatory");
            c.For(a => string.Format("{0:dd/MM/yyyy}", a.DateRequested)).Named("Date Requested");
            c.For(a => string.Format("{0:dd/MM/yyyy}", a.DateDeadline)).Named("Deadline Date");
            c.For(a => string.Format("{0:dd/MM/yyyy}", a.DateReceived)).Named("Date Received");         
            c.For(a => a.Comment).Named("Comment");
            c.For(a => a.Name).Named("Checklist type");
            c.For(a => @:<a href="www.google.com" />);
        }
        )
    </p>
    </span>
</div>

Any help would be welcomed.

UPDATE - based on archil's post, my new code has become:

@model Example.Models.ExampleItems

@{
    ViewBag.Title = "Example Items";

    Func<dynamic, object> updateLink = @<a href="#?w=500" rel="Checklist_Popup" class="poplight">@item</a>;
}

<div id="ExampleContentInnerContainer">
<h2>Example Items</h2>

<div id="ExampleListGrid">
    <span class="ExampleGrid">
    <p>
        @Html.Grid(Model.ExampleList).Columns(c =>
        {
            c.For(a => a.Example.Mandatory == true ? "Yes" : "No").Named("Mandatory");
            c.For(a => string.Format("{0:dd/MM/yyyy}", a.DateRequested)).Named("Date Requested");
            c.For(a => string.Format("{0:dd/MM/yyyy}", a.DateDeadline)).Named("Deadline Date");
            c.For(a => string.Format("{0:dd/MM/yyyy}", a.DateReceived)).Named("Date Received");         
            c.For(a => a.Comment).Named("Comment");
            c.For(a => a.Name).Named("Checklist type");
            c.For(a => updateLink("Update"));        
        }
        )
    </p>
    </span>
</div>

0

2 Answers 2

2

Take a look at templated razor delegates. There you could do your link generation

Sign up to request clarification or add additional context in comments.

Comments

0

You could try by wrapping "<a>...</a>" in "@<text>...</text>" tag. In your case it would look like so:

@model Example.Models.ExampleItems

@{
    ViewBag.Title = "Example Items";
}

<div id="ExampleContentInnerContainer">
<h2>Example Items</h2>

<div id="ExampleListGrid">
    <span class="ExampleGrid">
    <p>
        @Html.Grid(Model.ExampleList).Columns(c =>
        {
            c.For(a => a.Example.Mandatory == true ? "Yes" : "No").Named("Mandatory");
            c.For(a => string.Format("{0:dd/MM/yyyy}", a.DateRequested)).Named("Date Requested");
            c.For(a => string.Format("{0:dd/MM/yyyy}", a.DateDeadline)).Named("Deadline Date");
            c.For(a => string.Format("{0:dd/MM/yyyy}", a.DateReceived)).Named("Date Received");         
            c.For(a => a.Comment).Named("Comment");
            c.For(a => a.Name).Named("Checklist type");
            c.For(a => @<text><a href="www.google.com" /></text>);
        }
        )
    </p>
    </span>
</div>

1 Comment

Hi, thanks for the response. When i try it this way, unfortunately i get: Cannot convert lambda expression to type 'object' because it is not a delegate type.

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.