Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

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

0.00/5 (No votes)
2 Nov 2013 1  
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:

//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; }
//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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here