1

I'm following the code on here in razor syntax. I end up with this:

I tried this:

@{Html.Grid("basic")
    .setCaption("Basic Grid")
    .addColumn(new Column("JobId")
        .setLabel("Id"))
    .addColumn(new Column("Title"))
    .addColumn(new Column("CreatedDate"))
    .setUrl(Url.Action("Jobs"))
    .setAutoWidth(true)
    .setRowNum(10)
    .setRowList(new int[]{10,15,20,50})
    .setViewRecords(true)
    .setPager("pager");}

and its displays nothing. I had it starting with just @ and it encoded the data.

2 Answers 2

3

Try:

@(new MvcHtmlString(Html.Grid("basic")
.setCaption("Basic Grid")
.addColumn(new Column("JobId")
    .setLabel("Id"))
.addColumn(new Column("Title"))
.addColumn(new Column("CreatedDate"))
.setUrl(Url.Action("Jobs"))
.setAutoWidth(true)
.setRowNum(10)
.setRowList(new int[]{10,15,20,50})
.setViewRecords(true)
.setPager("pager").ToString())

Grid should return MvcHtmlString (or just IHtmlString) if you want it not to be encoded. The best solution is to write extension method called ToMvcHtmlString(), that returns proper value. Then you would just use Html.Grid().ToMvcHtmlString(). It is better than creating objects inside of view.

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

2 Comments

I'm looking at their source, seems they do not return a string, but some object.
@Lol coder: ToString() method surely returns string. Look at this method.
0

Try this:

@{ var grid = Html.Grid("basic")
.setCaption("Basic Grid")
.addColumn(new Column("JobId")
    .setLabel("Id"))
.addColumn(new Column("Title"))
.addColumn(new Column("CreatedDate"))
.setUrl(Url.Action("Jobs"))
.setAutoWidth(true)
.setRowNum(10)
.setRowList(new int[]{10,15,20,50})
.setViewRecords(true)
.setPager("pager");
}

Html.Raw(grid.ToString());

Better is that grid.ToString() returns an IHtmlString so you don't need to Html.Raw it

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.