Section 62 Utilizing research features in asp internet mvc



Backlink for code samples utilised in the demo
http://csharp-online video-tutorials.blogspot.com/2013/07/component-62-implementing-research.html

Backlink for csharp, asp.internet, ado.web, dotnet basic principles, mvc and sql server video tutorial playlists
http://www.youtube.com/user/kudvenkat/playlists

In this video, we will go over, applying lookup web site in an asp.net mvc software. We ought to be equipped to search by Staff Identify and Gender.

We will be using table tblEmployee for this demo. Use the script down below to make and populate the table with sample knowledge.
Develop desk tblEmployee
(
ID int identity primary key,
Name nvarchar(50),
Gender nvarchar(10),
Electronic mail nvarchar(50)
)

Insert into tblEmployee values(‘Sara Nani’, ‘Female’, ‘Sara.Nani@exam.com’)
Insert into tblEmployee values(‘James Histo’, ‘Male’, ‘James.Histo@take a look at.com’)
Insert into tblEmployee values(‘Mary Jane’, ‘Female’, ‘Mary.Jane@examination.com’)
Insert into tblEmployee values(‘Paul Sensit’, ‘Male’, ‘Paul.Sensit@take a look at.com’)

Action 1: Make an vacant asp.net mvc 4 application.

Step 2: Generate ADO.Internet entity facts design from database applying table tblEmployee. Modify the entity identify from tblEmployee to Staff. Conserve improvements and establish the software.

Step 3: Insert HomeController with the next settings.
a) Controller identify = HomeController
b) Template = MVC controller with read/write steps and sights, employing Entity Framework
c) Model course = Worker
d) Data context course = SampleDBContext
e) Sights = Razor

Step 4: Modify the Index() motion technique in HomeController as revealed beneath.
general public ActionResult Index(string searchBy, string look for)

if (searchBy == “Gender”)
research == null).ToList())

else

return Check out(db.Employees.In which(x =] x.Title.StartsWith(look for)

Action 5: Duplicate and paste the subsequent code in Index.cshtml watch.
@model IEnumerable[MVCDemo.Models.Employee]

@
ViewBag.Title = “Index”

[div style=”font-family:Arial”]
[h2]Worker Listing[/h2]
[p]
@working with (@Html.BeginForm(“Index”, “Property”, FormMethod.Get))

[b]Research By:[/b]
@Html.RadioButton(“searchBy”, “Title”, correct) [text]Identify[/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(product =] product.Title)
[/th]
[th]
@Html.DisplayNameFor(design =] design.Gender)
[/th]
[th]
@Html.DisplayNameFor(product =] product.Email)
[/th]
[th]Action[/th]
[/tr]
@if (Model.Rely() == )

[tr]
[td colspan=”4″]
No information match research criteria
[/td]
[/tr]

else

foreach (var item in Product)

@Html.ActionLink(“Aspects”, “Aspects”, new id = item.ID )

[/table]
[/div]

Remember to make absolutely sure to switch [ with LESSTHAN and ] with GREATERTHAN symbol.

resource

Leave a Reply

Your email address will not be published. Required fields are marked *