Click here to Skip to main content
15,887,746 members
Articles / Web Development / CSS
Tip/Trick

A Simple ASP.NET MVC Grid with Multilingual Support+Drop Down Menu

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
2 Nov 2013CPOL 11.2K   4  
Using grid and search grid using Ajax or without Ajax, and using Resource Files to enable multi language support

Introduction

In this source code, I've tried to combine a very simple ASP.NET MVC application without using any database, + showing results in Grid, Search via customer name, and using resource files to enable multi-language support.

Using the Code

This solution has 2 projects, Common (class library) and Application. Common project contains only the resource files required to multi-language support of the application.

WebApplication uses the default Visual Studio 2012 template. I have added a simple Customer model to use in project (edit, search and create) views for this model had been added to.

To search customer grid, JQuery UI auto complete facility has been used in search textbox. Also it's possible for you to run the grid partially or with a submit button:

C#
//creating Model

public class CustomerModel
    {
        private static List<CustomerModel> _list = null;

        private static int count = 0;
        public CustomerModel()
        {
            count++;
            Id = count;
        }
        [Required]
        public int Id { get; set; }

        [StringLength(20, ErrorMessage = "مقدار وارد شده بیش از حد مجاز است")]
        [Display(Name = "Name", ResourceType = typeof(Resource))]
        [Required(ErrorMessageResourceName = "Err_IsRequired", ErrorMessageResourceType = typeof(Resource))]
        public string Name { get; set; }

        [StringLength(30, ErrorMessage = "مقدار وارد شده بیش از حد مجاز است")]
        [Required(ErrorMessageResourceName = "Err_IsRequired", 
        ErrorMessageResourceType = typeof(Resource))]
        [Display(Name = "LastName", ResourceType = typeof(Resource))]
        public string LastName { get; set; }

        [Required(ErrorMessageResourceName = "Err_IsRequired", 
        ErrorMessageResourceType = typeof(Resource))]
        [Display(Name = "Gender", ResourceType = typeof(Resource))]
        public int Gender { get; set; }

        [Required(ErrorMessageResourceName = "Err_IsRequired", 
        ErrorMessageResourceType = typeof(Resource))]
        [Display(Name = "EducationId", ResourceType = typeof(Resource))]
        public int EducationId { get; set; }
C#
//this is the index view of customer using grid and search method

@using (Html.BeginForm("Index", "Customer", 
FormMethod.Post, new { id = "searchForm" }))
{
    @Html.EditorFor(c => c.SearchTerm)
    <button class="action" style="float: none" 
    onclick="search();return false;">
    <span class="activeIcon icon198"></span>
    <span class="label blue">Search</span></button>
    <div id="divResult">
        @Html.Partial("Grid", Model.ResultList)
    </div>
}
@section Scripts {
    @Scripts.Render("~/bundles/jqueryui")
    <script type="text/javascript">
        function createCs() {
            $('div#container').load('customer/create');
        }
        function search() {
            //post normally
            //uses input name as parameter in action
            document.forms["searchForm"].submit();

            //post with ajax
            //var t = $('input#SearchTerm').val();
            //$('#divResult').load('/customer/Grid?term=' + t);
        }
        $(function () {
            $("input#SearchTerm").autocomplete({
                source: '@Url.Action("GetCustomersJson", "Customer")'
            });

            $("table tr:even").addClass("evenTr");
            $("table tr:odd").addClass("oddTr");
        });
    </script>
}
@section siteCss{
    @Styles.Render("~/Content/themes/base/css")
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) DPI
Iran (Islamic Republic of) Iran (Islamic Republic of)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --