Webmatrix – a bit beyond Hello World ;)

It’s about time to see what other things WebMatrix can do out of the box.

Let’s make something more.. personal.

Fire up webmatrix and create an Empty Website called.. “myContacts” then add one page, index.cshtml will do fine but I will name mine default.cshtml 😀

Mine looks like this:

Then we add a database. WebMatrix has database connectivity so why won’t we use it? Let’s go!

At the lower part of the webmatrix IDE, there is a Menu Item that says “Databases”. Click that and it will show you the databases page.

Right smack in the middle, you will find what looks to be a Hyperlink to add a database to our site. Click that and create a database for your contacts.

That action will give you a blank database, which is useless. So go ahead and create a table to hold the data for your contacts.

I made one table and it looks like this on my screen

Add some data

And we are set to go..

Here is the code:

<!DOCTYPE
html>

@{


var myDataSource = Database.Open(“myContacts”);


var myContactTable = myDataSource.Query(“Select * from tblContacts”);

}

<html
lang=”en”>


<head>


<meta
charset=”utf-8″
/>


<title></title>


</head>


<body>


<ul>


@foreach(var contactInfo in myContactTable)

{


<li>@contactInfo.name @contactInfo.phoneNum</li>

}

 


</ul>

 


</body>

</html>

Run it. It works.

 

Advertisements
This entry was posted in Computers and Internet. Bookmark the permalink.

One Response to Webmatrix – a bit beyond Hello World ;)

  1. jentrinanes says:

    What I like about WebMatrix is the inclusion of the Razor syntax, Layout pages and reusable HTML helpers 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s