Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
dTub
Скачать

Part 62 Implementing search functionality in asp net mvc

Автор: kudvenkat

Загружено: 2013-07-26

Просмотров: 210004

Описание:

Link for code samples used in the demo
http://csharp-video-tutorials.blogspo...

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
   / @aarvikitchen5572  

Link for csharp, asp.net, ado.net, dotnet basics, mvc and sql server video tutorial playlists
   / kudvenkat  

In this video, we will discuss, implementing search page in an asp.net mvc application. We should be able to search by Employee Name and Gender.

We will be using table tblEmployee for this demo. Use the script below to create and populate the table with sample data.
Create table tblEmployee
(
ID int identity primary key,
Name nvarchar(50),
Gender nvarchar(10),
Email nvarchar(50)
)

Insert into tblEmployee values('Sara Nani', 'Female', 'Sara.Nani@test.com')
Insert into tblEmployee values('James Histo', 'Male', 'James.Histo@test.com')
Insert into tblEmployee values('Mary Jane', 'Female', 'Mary.Jane@test.com')
Insert into tblEmployee values('Paul Sensit', 'Male', 'Paul.Sensit@test.com')

Step 1: Create an empty asp.net mvc 4 application.

Step 2: Generate ADO.NET entity data model from database using table tblEmployee. Change the entity name from tblEmployee to Employee. Save changes and build the application.

Step 3: Add HomeController with the following settings.
a) Controller name = HomeController
b) Template = MVC controller with read/write actions and views, using Entity Framework
c) Model class = Employee
d) Data context class = SampleDBContext
e) Views = Razor

Step 4: Modify the Index() action method in HomeController as shown below.
public ActionResult Index(string searchBy, string search)
{
if (searchBy == "Gender")
{
return View(db.Employees.Where(x =] x.Gender == search || search == null).ToList());
}
else
{
return View(db.Employees.Where(x =] x.Name.StartsWith(search) || search == null).ToList());
}
}

Step 5: Copy and paste the following code in Index.cshtml view.
@model IEnumerable[MVCDemo.Models.Employee]

@{
ViewBag.Title = "Index";
}
[div style="font-family:Arial"]
[h2]Employee List[/h2]
[p]
@using (@Html.BeginForm("Index", "Home", FormMethod.Get))
{
[b]Search By:[/b]
@Html.RadioButton("searchBy", "Name", true) [text]Name[/text]
@Html.RadioButton("searchBy", "Gender") [text]Gender[/text][br /]
@Html.TextBox("search") [input type="submit" value="search" /]

}
[/p]
[table border="1"]
[tr]
[th]
@Html.DisplayNameFor(model =] model.Name)
[/th]
[th]
@Html.DisplayNameFor(model =] model.Gender)
[/th]
[th]
@Html.DisplayNameFor(model =] model.Email)
[/th]
[th]Action[/th]
[/tr]
@if (Model.Count() == 0)
{
[tr]
[td colspan="4"]
No records match search criteria
[/td]
[/tr]
}
else
{
foreach (var item in Model)
{
[tr]
[td]
@Html.DisplayFor(modelItem =] item.Name)
[/td]
[td]
@Html.DisplayFor(modelItem =] item.Gender)
[/td]
[td]
@Html.DisplayFor(modelItem =] item.Email)
[/td]
[td]
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
[/td]
[/tr]
}
}
[/table]
[/div]

Please make sure to replace [ with LESSTHAN and ] with GREATERTHAN symbol.

Part 62   Implementing search functionality in asp net mvc

Поделиться в:

Доступные форматы для скачивания:

Скачать видео mp4

  • Информация по загрузке:

Скачать аудио mp3

Похожие видео

Part 63   Implement paging in asp net mvc

Part 63 Implement paging in asp net mvc

ViewModels в приложениях ASP.NET MVC — как это работает

ViewModels в приложениях ASP.NET MVC — как это работает

Part 79   Areas in asp net mvc

Part 79 Areas in asp net mvc

Part 64   Implement sorting in asp net mvc

Part 64 Implement sorting in asp net mvc

Внезапно миролюбивый Путин снова на связи (English subtitles)

Внезапно миролюбивый Путин снова на связи (English subtitles)

Part 52   Partial views in mvc

Part 52 Partial views in mvc

Jquery Live Search | Search Functionality | ASP.NET MVC

Jquery Live Search | Search Functionality | ASP.NET MVC

jQuery Datatable and Asp.Net MVC Integration

jQuery Datatable and Asp.Net MVC Integration

Asp.net MVC tutorial for Beginner

Asp.net MVC tutorial for Beginner

Part 77   Custom action filters in asp net mvc

Part 77 Custom action filters in asp net mvc

Part 80   StringLength attribute in asp net mvc

Part 80 StringLength attribute in asp net mvc

ASP.NET Core MVC CRUD Operations using .NET 8 and Entity Framework Core - MVC For Beginners Tutorial

ASP.NET Core MVC CRUD Operations using .NET 8 and Entity Framework Core - MVC For Beginners Tutorial

Загадочная авария Адама Кадырова. Подробности ДТП в Чечне и политическая подоплека происшествия

Загадочная авария Адама Кадырова. Подробности ДТП в Чечне и политическая подоплека происшествия

ASP.NET MVC Tutorials - Implement Search Functionality in ASP.NET MVC.

ASP.NET MVC Tutorials - Implement Search Functionality in ASP.NET MVC.

Part 65   Deleting multiple rows in mvc

Part 65 Deleting multiple rows in mvc

MVC project and SQL server deployment using Visual Studio (smarterasp.net)

MVC project and SQL server deployment using Visual Studio (smarterasp.net)

Part 92   Ajax with asp net mvc

Part 92 Ajax with asp net mvc

jQuery Datepicker in Asp.Net MVC

jQuery Datepicker in Asp.Net MVC

Липсиц про рекордный рост цен, будущее криптовалют и развал РЖД🎙️ Честное слово с Липсицем

Липсиц про рекордный рост цен, будущее криптовалют и развал РЖД🎙️ Честное слово с Липсицем

Сын Кадырова в больнице после ДТП. Деревня под Челябинском без тепла. Что будет с теневым флотом РФ

Сын Кадырова в больнице после ДТП. Деревня под Челябинском без тепла. Что будет с теневым флотом РФ

© 2025 dtub. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: infodtube@gmail.com