Does Grid.MVC support the .aspx view engine?

Jul 16, 2013 at 2:12 PM
Does Grid.MVC support the .aspx view engine?

https://gridmvc.codeplex.com/

or does it only support Razor .cshtml?

If yes, please show a sample .aspx page using Grid.MVC model

Thanks,
-Leo Cono, www.MobileDeliver.com
Coordinator
Jul 16, 2013 at 3:36 PM
Hi,

There was a problem to render the grid on aspx view engine. I fixed them and commit changes to the source repository. You can take them. I'll release the next version in a few month.

All documentation samples uses Razor engine, but now you can uses this samples to render grid on ASPX page:
<%@ Import Namespace="GridMvc.Html" %>
<%@ Import Namespace="GridMvc.Sorting" %>


<%= Html.Grid(Model).Named("ordersGrid").Columns(columns =>
    {
        /* Adding not mapped column, that renders body, using inline Razor html helper */
        columns.Add()
                .Encoded(false)
                .Sanitized(false)
                .SetWidth(30)
                .RenderValueAs(o => Html.ActionLink("Edit", "Edit", new { id = o.OrderID }, new { @class = "modal-link" }));

        /* Adding "OrderID" column: */
        columns.Add(o => o.OrderID)
                .Titled("Number")
                .SetWidth(100);

        /* Adding "OrderDate" column: */
        columns.Add(o => o.OrderDate, "OrderCustomDate")
                .Titled("Date")
                .SortInitialDirection(GridSortDirection.Descending)
                .Format("{0:dd/MM/yyyy}")
                .SetWidth(110);

        /* Adding "CompanyName" column: */
        columns.Add(o => o.Customer.CompanyName)
                .Titled("Company Name")
                .ThenSortByDescending(o => o.OrderID)
                .SetFilterWidgetType("CustomCompanyNameFilterWidget");

    }).SetRowCssClasses(item => item.Customer.IsVip ? "warning" : string.Empty).WithPaging(15).Sortable().Filterable().WithMultipleFilters() %>
Jul 16, 2013 at 3:51 PM
Hi Bukharin - Now that I have this .aspx code, I can use .aspx master pages.

Thanks,
-Leo Cono, www.MobileDeliver.com
Jul 16, 2013 at 5:02 PM
Bukharin -

I got the following error message:
GridMvc.Html.HtmlGrid<Models.Schedule> does not contain a definition for 'Named' and no extension method 'Named' accepting a first argument of type 'GridMvc.Html.HtmlGrid<Models.Schedule>' could be found (are you missing a using directive or an assembly reference?)

Please advise.

Thanks,
-Leo Cono, www.MobileDeliver.com
Coordinator
Jul 16, 2013 at 5:07 PM
The current release version does not contain Named method
If you want use current version you also need to call ToHtmlString method:
<%@ Import Namespace="GridMvc.Html" %>
<%@ Import Namespace="GridMvc.Sorting" %>


<%= Html.Grid(Model).Columns(columns =>
    {
        /* Adding not mapped column, that renders body, using inline Razor html helper */
        columns.Add()
                .Encoded(false)
                .Sanitized(false)
                .SetWidth(30)
                .RenderValueAs(o => Html.ActionLink("Edit", "Edit", new { id = o.OrderID }));

        /* Adding "OrderID" column: */
        columns.Add(o => o.OrderID)
                .Titled("Number")
                .SetWidth(100);

        /* Adding "OrderDate" column: */
        columns.Add(o => o.OrderDate, "OrderCustomDate")
                .Titled("Date")
                .SortInitialDirection(GridSortDirection.Descending)
                .Format("{0:dd/MM/yyyy}")
                .SetWidth(110);

        /* Adding "CompanyName" column: */
        columns.Add(o => o.Customer.CompanyName)
                .Titled("Company Name")
                .ThenSortByDescending(o => o.OrderID);

    })..WithPaging(15).Sortable().Filterable().ToHtmlString() %>
Jul 16, 2013 at 8:34 PM
Edited Jul 16, 2013 at 8:35 PM
Hi Bukharin -

The grid is now displaying but there are no styles applied. I copied all of the images, javascript and css files into my Visual Studio project.
However, I am not using Razor. Thus the styles must be applied with the master page right?
Here is a screen shot:

Image
Jul 16, 2013 at 8:38 PM
this is what is in my Master Page:
<meta name="viewport" content="width=device-width" />
<link href="~/Content/Gridmvc.css" rel="stylesheet" />
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.9.1.min.js"></script>
<script src="~/Scripts/gridmvc.min.js"></script>
Coordinator
Jul 17, 2013 at 4:16 AM
I can't say why browser not apply referenced styles. You can diagnose this, using developer tools (press F12 in the browser). But it can be by following reasons
  1. Ensure that all stylesheet files exists
  2. May be ASPX engine not process "~" symbol as a web app root path. Try specify absolute URL to the files, like: <link href="/Content/bootstrap.min.css" rel="stylesheet" />
Jul 17, 2013 at 11:20 AM
BTW, thanks for the F12 tip. I like this debugging tool a lot and did not know about it.

I think I know the reason why the grid style is not applied.

/Views/Shared folder includes:
_Grid.cshtml
_GridPager.cshtml
These are Razor View Engine files.

The style for the Div is grid-outer paged
I did a search in the project files and found this style is being applied to the following
<div id="@gridClinetId" class="grid-outer @(Model.EnablePaging ? "paged" : string.Empty)">
this is in _Grid.cshtml

I think you cannot mix .cshtml with .aspx. i.e. ASPX View Engine with Razor View Engine.

Please advse.

Thanks,
-Leo Cono, www.MobileDeliver.com
Coordinator
Jul 17, 2013 at 11:24 AM
If you see grid table in the browser - it mean that razor view engine works correct. And you can combine Razor and ASPX engine without any problems in your MVC app.
Jul 17, 2013 at 11:59 AM
Ok you were correct about the .css path having the ~.
With F12 I saw that some .css had ~ and some .css had ../../ in the path.
~ works in a .cs file but was not working in .aspx file
Thus I replaced ~ to ../../

Now the Grid looks like this:
Image

It appears that the styles are being applied but the grid images are not applied.
I looked at GridMVC.css and it appears that the images are coded as binary and embedded as binary in the GridMVC.css

Also note that I had to remove
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
because it was messing up my overall Web Site style. But bootstrap.min.css styles are not for Grid.mvc right?
bootstrap.min.css is only for the web page containig the Grid.mvc right?
Grid.mvc style is configured only by GridMVC.css right?

Thanks,
Leo Cono, www.MobileDeliver.com
Coordinator
Jul 17, 2013 at 12:34 PM
Grid.mvc uses bootstrap styles as default styles. Gridmvc.css - only adds some styles that does not contains in bootstrap. I.e. grid render only base layout of table like <table class="table"> ... </table>. You can apply your own styles for this tags or use bootstrap. Also you can copy paste only bootstrap table styles from boostrap.css to your web sites stylesheets, if you want that grid.mvc looks like in demo and no other styles was applied to your web site. It depends how you want the grid looks.
Jul 17, 2013 at 12:38 PM
Is it possible to create a new GridMvc.css file that is inclusive of all the styles the grid needs and is not dependent on bootstrap?
Coordinator
Jul 17, 2013 at 5:35 PM
Yes, but bootstrap - is a separate solution, which has updates and I need to make this action each time then bootstrap updates.
Jul 17, 2013 at 6:08 PM
Bukharin -

Yes I agree. You have to keep making updates with Bootstrap.
However, with that said, to support the .ASPX View Engine, why not create a "Second" or "Alternate" GridMvc.css file so that I can use your grid with the .aspx view engine. This way you can have two versions of GridMvc.css (one that will not be updated and one that will be used with .aspx view engine.)

Thanks,
-Leo, www.MobileDeliver.com
Coordinator
Jul 17, 2013 at 6:48 PM
It does not matter which view engine you are using. Grid only provide tool for building table of data, with some features (paging, sorting... ). By default it uses bootstrap styles. If you say: Ok, I don't want to use default styles. - in this case you need to decide how your grid will be look and create your own css styles.

In your case, as I understand - you don't want to use bootstrap, but you want that grid looks like bootstrap. I said that you need to copy and paste some bootstrap style in separate css file. Other people wants that grid look like bootstrap, except font etc. And I need create an another version for this purpose? This is the customization, and here everyone decides - what styles use.
Jul 17, 2013 at 6:59 PM
Bukharin - most developers want to use the Grid as a control. Most people are not interested in the style of a specific web site. Bootstrap style is a web site style not a Grid style. Developers have their own styles for a web page. When I add the bootstrap style to my .aspx view engine web site everything is distorted. You did not develop this Grid Control has an open source web page. You developed an Open Source Grid Control. Thus, the grid should have it's own default .css file that is not dependent on the .css file of a particular web page.
Coordinator
Jul 17, 2013 at 7:09 PM
"Developers have their own styles for a web page..." - yes, it means that you has your own styles for standard html tables, which uses the grid.

I don't know which styles uses your web site, and if I create grid own styles - still does not fit the web site design. And if you don't want to use default styles - you need to create you own grid style. according design, that uses your web site (font, color, size etc).
Jul 17, 2013 at 7:19 PM
Bukharin - thanks for developing this Grid Control.

I like it. :)

I just wish the Grid came with a default "out-of-the-box" .css file that is not dependent on any other .css.
In other words, a .css file that will not distort my web site.

All The Best,
-Leo Cono, www.MobileDeliver.com
Apr 3, 2014 at 1:30 PM
I tried this but while using ToHtmlString It is giving me following error in my MVC project.

System.Web.HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerWrapper'. ---> System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.IO.InvalidDataException: Specified view name for Grid.Mvc not found. ViewName: _Grid


Can you help me with this? If you have sample project of using Grid.MVC using in .aspx , it will be great.

Thanks,
Darshan

Bukharin wrote:
The current release version does not contain Named method
If you want use current version you also need to call ToHtmlString method:
<%@ Import Namespace="GridMvc.Html" %>
<%@ Import Namespace="GridMvc.Sorting" %>


<%= Html.Grid(Model).Columns(columns =>
    {
        /* Adding not mapped column, that renders body, using inline Razor html helper */
        columns.Add()
                .Encoded(false)
                .Sanitized(false)
                .SetWidth(30)
                .RenderValueAs(o => Html.ActionLink("Edit", "Edit", new { id = o.OrderID }));

        /* Adding "OrderID" column: */
        columns.Add(o => o.OrderID)
                .Titled("Number")
                .SetWidth(100);

        /* Adding "OrderDate" column: */
        columns.Add(o => o.OrderDate, "OrderCustomDate")
                .Titled("Date")
                .SortInitialDirection(GridSortDirection.Descending)
                .Format("{0:dd/MM/yyyy}")
                .SetWidth(110);

        /* Adding "CompanyName" column: */
        columns.Add(o => o.Customer.CompanyName)
                .Titled("Company Name")
                .ThenSortByDescending(o => o.OrderID);

    })..WithPaging(15).Sortable().Filterable().ToHtmlString() %>