Click here to Skip to main content
15,881,715 members
Articles / Web Development / ASP.NET

MVC Basic Site: Step 3 – Dynamic Layouts and Site Admin with: AJAX, jqGrid, Controller Extensions, HTML Helpers, and more

Rate me:
Please Sign up or sign in to vote.
4.96/5 (72 votes)
25 Oct 2013Ms-PL28 min read 205.8K   13.1K   186  
This article provides the implementation of dynamic layouts and web site administration in ASP.NET MVC4.0 by using: AJAX, jqGrid, Custom Action Results, Controller Extension, HTML Helpers, and more.
@using MvcBasicSite.Models.Grid;
@{
    ViewBag.Title = Resources.Resource.VisitorLogIndexTitle;
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
    //
    int pageSize = 20;
    if (Session["VisitorLogGridSettings"] != null)
    {
        //
        // Get from cache the last page zise selected by the user. 
        //
        GridSettings grid = new GridSettings((string)Session["VisitorLogGridSettings"]);
        pageSize = grid.PageSize;
    }
    //
    // Restore the last search params from cache.
    //
    string startDate = (Session["StartDate"] == null
        ? string.Empty
        : ((DateTime)Session["StartDate"]).ToShortDateString());
    string endDate = (Session["EndDate"] == null
        ? string.Empty
        : ((DateTime)Session["EndDate"]).ToShortDateString());
}
<table>
    <tr>
        <td style="text-align: right; margin-top: 0px;">
            @using (Ajax.BeginForm("Search", "VisitorLog", 
                new AjaxOptions
                {
                    HttpMethod = "GET",
                    InsertionMode = InsertionMode.Replace,
                    UpdateTargetId = "jqGrid",
                    OnSuccess = "showGrid()"
                }))
            {
                <table>
                    <tr>
                        <td>
                            <label>@Resources.Resource.VisitorLogIndexFrom</label>
                            <input type="text" id="from" name="from" data-datepicker="true" value="@startDate" />
                        </td>
                        <td>
                            <label>@Resources.Resource.VisitorLogIndexTo</label>
                            <input type="text" id="to" name="to" data-datepicker="true" value="@endDate" />
                        </td>
                        <td style="text-align: right; margin-top: 0px;">
                            <input type="submit" name="_search" value="@Resources.Resource.VisitorLogApplyFilter" class="searchButton" />
                        </td>
                    </tr>
                </table>
            }
        </td>
    </tr>
</table>
<div id="jqGrid">
    @Html.Partial("_VisitorLogGrid")
</div>
<script type="text/javascript">
    var paramFromView = {
        DeleteAllCaption: '@Resources.Resource.VisitorLogDeleteAllCaption',
        ClearGridUrl: '@Url.Content("~/VisitorLog/ClearGridData")',
        DeleteAllConfirmationMessage: '@Resources.Resource.VisitorLogDeleteAllDataConfirmation',
        Url: '@Url.Content("~/VisitorLog/GetData")',
        Width: 790,
        Height: 464,
        Caption: '@Resources.Resource.VisitorLogIndexTitle',
        VisitorName: '@Resources.Resource.VisitorLogIndexVisitorName',
        StartDate: '@Resources.Resource.VisitorLogIndexStartDate',
        EndDate: '@Resources.Resource.VisitorLogIndexEndDate',
        WasTimeOut: '@Resources.Resource.VisitorLogIndexWasTimeOut',
        Actions: '@Resources.Resource.VisitorLogIndexActions',
        PageSize: @pageSize
    }
</script>
@section scripts
{
    @Content.Script("VisitorLogGrid.js", Url)
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Romania Romania
I have about 20 years experiences in leading software projects and teams and about 25 years of working experience in software development (SW Developer, SW Lead, SW Architect, SW PM, SW Manager/Group Leader).

Comments and Discussions