First, I created a new project and then used the Library Package Manager to add the (Code First) Entity Framework (CTP5) to the project.




I then added a class called Post to the Models folder with the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
namespace MobileBlog.Models
{
public class Post
{
public int ID { get; set; }
public string Title { get; set; }
[DataType(DataType.MultilineText)]
public string Content { get; set; }
public DateTime PublishDate { get; set; }
}
public class PostDBContext : DbContext
{
public DbSet<Post> Posts { get; set; }
}
}
This re-creates the same scheme I had for the PHP/MySQL Mobile Blog project. I also then created another class to the Models folder called PostInitializer to re-create the database and seed it with data as required. Here is the code for that class:
using System;
using System.Collections.Generic;
using System.Data.Entity.Database;
namespace MobileBlog.Models
{
public class PostInitializer : DropCreateDatabaseIfModelChanges<PostDBContext>
{
protected override void Seed(PostDBContext context)
{
var posts= new List<Post> {
new Post { Title = "My new blog",
Content = "This is my first blog post...",
PublishDate= DateTime.Now},
new Post { Title = "Second post",
Content = "This is my second blog post. Hi!",
PublishDate= DateTime.Now}
};
posts.ForEach(d => context.Posts.Add(d));
}
}
}
That requires a change to the web.config (for the connection string) and the Global.asax.cs file.
To the Application_Start() in the Global.asax.cs file I added the following line:
DbDatabase.SetInitializer<PostDBContext>(new PostInitializer());
…as well as this:
using System.Data.Entity.Database;
using MobileBlog.Models;
The connection string for the web.config file is as follows:
<connectionStrings>
<add name="PostDBContext"
connectionString="Server=.\SQLEXPRESS;
Database=Posts;Trusted_Connection=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
Going into the Views/Shared folder no I modified the _Layout.cshtml file to be a good template for the project and to be in HTML5 format as well as to use the JQuery CDN to import the JQuery and JQuery Mobile frameworks.
<!DOCTYPE html>
<html lang="en-us" >
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MobileBlog</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" />
<script src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>@ViewBag.HeaderString</h1>
</div>
<div data-role="content">
@RenderBody()
</div>
<div data-role="footer"><h1>- MobileBlog -</h1></div>
</div>
</body>
</html>
I then added a HomeController with the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MobileBlog.Models;
namespace MobileBlog.Controllers
{
public class HomeController : Controller
{
PostDBContext db = new PostDBContext();
public ActionResult Index()
{
ViewBag.HeaderString = "Welcome!";
return View();
}
public ActionResult Create()
{
ViewBag.HeaderString = "Create New Post";
return View();
}
public ActionResult Read()
{
ViewBag.HeaderString = "Read Blog";
var posts = from p in db.Posts
select p;
return View(posts.ToList());
}
public ActionResult About()
{
ViewBag.HeaderString = "About MobileBlog";
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public string SavePost(string title, string content)
{
Post post = new Post();
post.Title = title;
post.Content = content;
post.PublishDate = DateTime.Now;
if (ModelState.IsValid)
{
db.Posts.Add(post);
db.SaveChanges();
return "SUCCESS";
}
else
{
return "FAILED";
}
}
}
}
From that controller I generated views for the following pages: About, Create, Index, and Read.
File: About.cshtml
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div data-role="fieldcontain">
<p><a href="http://windows2008hosting.asphostportal.com">MobileBlog</a></p>
<p>Created by: <a href="http://twitter.com/jervis">Jervis</a></p>
<p>Powered by: <a href="http://jquerymobile.com">JQuery Mobile</a></p>
</div>
File: Index.cshtml
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<ul data-role="listview">
<li>
@Html.ActionLink("Create New Post", "Create")
</li>
<li>
@Html.ActionLink("Read Blog", "Read")
</li>
<li>
@Html.ActionLink("About MobileBlog", "About")
</li>
</ul>
File: Create.cshtml
@model MobileBlog.Models.Post
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script type="text/javascript">
function resetTextFields()
{
$("#Title").val("");
$("#Content").val("");
}
function onSuccess(data, status)
{
resetTextFields();
// Notify the user the new post was saved
$("#notification").fadeIn(2000);
data = $.trim(data);
if(data == "SUCCESS")
{
$("#notification").css("background-color", "#ffff00");
$("#notification").text("The post was saved");
}
else
{
$("#notification").css("background-color", "#ff0000");
$("#notification").text(data);
}
$("#notification").fadeOut(5000);
}
$(document).ready(function() {
$("form[action$='SavePost']").submit(function () {
$.ajax({
url: $(this).attr("action"),
type: "post",
data: $(this).serialize(),
success: onSuccess
});
return false;
});
$("#cancel").click(function(){
resetTextFields();
});
});
</script>
using (Html.BeginForm("SavePost", "Home", FormMethod.Post))
{
<div data-role="content">
<form id="newPostForm">
<div data-role="fieldcontain">
@Html.LabelFor(model => model.Title, "Post Title")
@Html.EditorFor(model => model.Title)
@Html.LabelFor(model => model.Content, "Post Content")
@Html.TextAreaFor(model => model.Content)
<fieldset class="ui-grid-a">
<div class="ui-block-a">@Html.ActionLink("Cancel", "Index", null, new { @data_role = "button" })</div>
<div class="ui-block-b"><button data-theme="b"
id="submit" type="submit">Submit</button></div>
</fieldset>
<h3 id="notification"></h3>
</div>
</form>
</div>
}
File: Read.cshtml
@model IEnumerable<MobileBlog.Models.Post>
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script type="text/javascript">
$(document).ready(function() {
$("#refresh").click(function(){
location.reload();
});
});
</script>
<button data-theme="b" data-role="button" data-iconpos="left" id="refresh" type="button" data-icon="refresh">Refresh</button>
<ul data-role="listview" data-theme="d" data-inset="true">
@foreach (var post in Model) {
<li><h2>@post.Title</h2>@post.Content<p class="ui-li-aside"><strong>@post.PublishDate</strong></p></li>
}
</ul>
So the code is familiar to the PHP code in most regards. Running the project in the Android emulator I get the same results as the PHP project before. BTW, I used the following address (because the Android emulator currently can’t use localhost for this type of thing):




Reasons why you must trust ASPHostPortal.com
Every provider will tell you how they treat their support, uptime, expertise, guarantees, etc., are. Take a close look. What they’re really offering you is nothing close to what ASPHostPortal does. You will be treated with respect and provided the courtesy and service you would expect from a world-class web hosting business.
You’ll have highly trained, skilled professional technical support people ready, willing, and wanting to help you 24 hours a day. Your web hosting account servers are monitored from three monitoring points, with two alert points, every minute, 24 hours a day, 7 days a week, 365 days a year. The followings are the list of other added- benefits you can find when hosting with us:
- DELL Hardware
Dell hardware is engineered to keep critical enterprise applications running around the clock with clustered solutions fully tested and certified by Dell and other leading operating system and application providers.
- Recovery Systems
Recovery becomes easy and seamless with our fully managed backup services. We monitor your server to ensure your data is properly backed up and recoverable so when the time comes, you can easily repair or recover your data.
- Control Panel
We provide one of the most comprehensive customer control panels available. Providing maximum control and ease of use, our Control Panel serves as the central management point for your ASPHostPortal account. You’ll use a flexible, powerful hosting control panel that will give you direct control over your web hosting account. Our control panel and systems configuration is fully automated and this means your settings are configured automatically and instantly.
- Excellent Expertise in Technology
The reason we can provide you with a great amount of power, flexibility, and simplicity at such a discounted price is due to incredible efficiencies within our business. We have not just been providing hosting for many clients for years, we have also been researching, developing, and innovating every aspect of our operations, systems, procedures, strategy, management, and teams. Our operations are based on a continual improvement program where we review thousands of systems, operational and management metrics in real-time, to fine-tune every aspect of our operation and activities. We continually train and retrain all people in our teams. We provide all people in our teams with the time, space, and inspiration to research, understand, and explore the Internet in search of greater knowledge. We do this while providing you with the best hosting services for the lowest possible price.
- Data Center
ASPHostPortal modular Tier-3 data center was specifically designed to be a world-class web hosting facility totally dedicated to uncompromised performance and security
- Monitoring Services
From the moment your server is connected to our network it is monitored for connectivity, disk, memory and CPU utilization – as well as hardware failures. Our engineers are alerted to potential issues before they become critical.
- Network
ASPHostPortal has architected its network like no other hosting company. Every facet of our network infrastructure scales to gigabit speeds with no single point of failure.
- Security
Network security and the security of your server are ASPHostPortal’s top priorities. Our security team is constantly monitoring the entire network for unusual or suspicious behavior so that when it is detected we can address the issue before our network or your server is affected.
- Support Services
Engineers staff our data center 24 hours a day, 7 days a week, 365 days a year to manage the network infrastructure and oversee top-of-the-line servers that host our clients’ critical sites and services.