Creating a Tasklist Application with ASP.NET MVC
2013-11-02 21:50
369 查看
Creating a Tasklist Application with ASP.NET MVC
1.Create Home controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace TaskList.Controllers
{
public class HomeController : Controller
{
private TaskListDBEntities db;
//Display a list of tasks
public ActionResult Index()
{
return View();
}
//Display a form for creating a new task
public ActionResult Create()
{
return View();
}
//Adding a new task to the database
public ActionResult CreateNew(string task)
{
//Add the new task to database
Tasks newTask = new Tasks
{
Task=task,
IsCompleted=false,
EntryDate=DateTime.Now,
};
db.Tasks.AddObject(newTask);
db.SaveChanges();
return RedirectToAction("Index");
}
//Mark a task as complete
public ActionResult Complete()
{
return RedirectToAction("Index");
}
}
}
2.Create Home and Create View
Home
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<div>
<h1>My Tasks</h1>
......displaying all tasks
<br /><br />
<a href="/Home/Create">Add new Task</a>
</div>
</body>
</html>
Create
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<div>
<h1>Add New Task</h1>
<form method="post" action="/Home/CreateNew">
<label for="task">Task:</label>
<input type="text" name="task" />
<br />
<input type="submit" value="Add Task" />
</form>
</div>
</body>
</html>
3.Add ADO Entity Framework
4.
1.Create Home controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace TaskList.Controllers
{
public class HomeController : Controller
{
private TaskListDBEntities db;
//Display a list of tasks
public ActionResult Index()
{
return View();
}
//Display a form for creating a new task
public ActionResult Create()
{
return View();
}
//Adding a new task to the database
public ActionResult CreateNew(string task)
{
//Add the new task to database
Tasks newTask = new Tasks
{
Task=task,
IsCompleted=false,
EntryDate=DateTime.Now,
};
db.Tasks.AddObject(newTask);
db.SaveChanges();
return RedirectToAction("Index");
}
//Mark a task as complete
public ActionResult Complete()
{
return RedirectToAction("Index");
}
}
}
2.Create Home and Create View
Home
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<div>
<h1>My Tasks</h1>
......displaying all tasks
<br /><br />
<a href="/Home/Create">Add new Task</a>
</div>
</body>
</html>
Create
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<div>
<h1>Add New Task</h1>
<form method="post" action="/Home/CreateNew">
<label for="task">Task:</label>
<input type="text" name="task" />
<br />
<input type="submit" value="Add Task" />
</form>
</div>
</body>
</html>
3.Add ADO Entity Framework
4.
相关文章推荐
- http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
- EF Database First with ASP.NET MVC: Creating the Web Application and Data Models开发遇到问题的解决办法
- 翻译:ASP.NET MVC Example Application over Northwind with Entity Framework
- ASP.NET MVC- VIEW Creating Page Layouts with View Master Pages Part 4
- [转]ASP.NET MVC 5 List Editor with Bootstrap Modals
- ASP.NET MVC #01, Create a Movie Database Application in 15 Minutes with ASP.NET MVC
- [译]Creating a Stock Widget in ASP.NET MVC Application
- Creating a Clean, Minimal-Footprint ASP.NET WebAPI Project with VS 2012 and ASP.NET MVC 4
- using Silverlight 4 in an ASP.NET MVC 3 application and accessing data with JSON
- Asp.net MVC 4 application with Flexigrid, jQuery UI, and jQuery validation
- [转]Sorting, Filtering, and Paging with the Entity Framework in an ASP.NET MVC Application (3 of 10)
- Sorting, Filtering, and Paging with the Entity Framework in an ASP.NET MVC Application
- 安装了VS2010 sp1 后再安装ASP.NET MVC 3.0的问题(Final Result: Installation failed with error code: (0x80070643), "安装时发生严重错误 " (Ela)
- 源码学习之ASP.NET MVC Application Using Entity Framework
- [转]ASP.NET MVC - Creating a DropDownList helper for enums
- ASP.NET MVC 将IList<T>导出Excel文档的泛型类(继承自ActionResult)
- LevenBlog2.0.7(With Asp.Net MVC1.0)发布-建议所有用户更新
- Intro to ASP.NET MVC 4 with Visual Studio [译六:从控制器中访问模型的数据]
- [视频]怎样提升asp.net mvc 软件的性能 - 微软免费视频Improving ASP.NET MVC Application Performance