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:
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; }
@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() {
document.forms["searchForm"].submit();
}
$(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")
}