由于自己也是才学习Web开发,可能写的东西比较简单,有兴趣的可以看,大牛跟大虾可以帮忙指出问题,可能里面专业术语不会太多,毕竟自己也不懂,还请见谅。
1、直接打开VS2010,创建一个新的MVC框架应用程序。
2、创建完成后,系统基本会将基础工作都做完了,自动生成文件,目录如下:
3、创建数据模型,在Models文件夹处,右击添加“新建项”,设置实体数据模型名称为“NorthWind.edmx”,按照提示一步一步往下,此处我只用一张表来做例子“Categories”。

4、更改控制器,添加Create、Edit、Detail几个方法。
namespace MvcApplication1.Controllers
{
        [HandleError]
         public class HomeController : Controller
        {
                NorthwindEntities northWind = new NorthwindEntities();

                 public ActionResult Index()
                {
                        var models = northWind.Categories.ToList();

                         return View(models);
                }

                [AcceptVerbs(HttpVerbs.Get)]
                 public ActionResult Edit( int id)
                {
                        var models = northWind.Categories.First(c => c.CategoryID == id);
                         return View(models);
                }

                [AcceptVerbs(HttpVerbs.Post)]
                 public ActionResult Edit( int categoryId, FormCollection form)
                {
                        var models = northWind.Categories.First(c => c.CategoryID == categoryId);
                        UpdateModel(models, new[] { "CategoryName", "Description" });
                        northWind.SaveChanges();

                         return RedirectToAction( "Index");
                }

                [AcceptVerbs(HttpVerbs.Get)]
                 public ActionResult Detail( int id)
                {
                        var models = northWind.Categories.First(c => c.CategoryID == id);
                         return View(models);
                }

                [AcceptVerbs(HttpVerbs.Get)]
                 public ActionResult Create()
                {
                        Categories category = new Categories();
                         return View(category);
                }

                [AcceptVerbs(HttpVerbs.Post)]
                 public ActionResult Create( int categoryId, FormCollection form)
                {
                        var models = northWind.Categories.FirstOrDefault(c => c.CategoryID == categoryId);

                         if (models== null)
                        {
                                Categories category = new Categories();
                                UpdateModel(category, new[] { "CategoryName", "Description" });
                                northWind.AddToCategories(category);
                                northWind.SaveChanges();
                                 return RedirectToAction( "Index");

                        }
                         else
                        {
                                 return RedirectToAction( "Create");
                        }                        
                }

                 public ActionResult About()
                {
                         return View();
                }
        }
}
5、创建视图,在相应的控制器处,直接右击,添加视图,各项选择都如下图。这边有个主意的地方就是,我一开始的时候选择强类型视图,怎么选择都是没有Categories,后来通过网上查询,发现是自己没有先编译生成。
6、在视图中,自己也尝试着进行简单的修改,当然不是CSS跟JS这些啦,毕竟还没到那层次。主要还是关键字的显示跟隐藏。
@Html.HiddenFor(model => model.CategoryID)
7、测试了 ValidationMessageFor与 ValidationMessage。
@Html.ValidationMessageFor(model => model.Description)
@Html.ValidationMessage("CategoryName ","*")
这两个的效果大家可以自己测试下。
8、最终效果。
9、遗留问题:
   最后还有2个问题在学习的时候未解决。a、路由:系统自动创建是MapRoute,add的方法我没试过;b、就是在编辑的时候如果我内容出现<>这种字符,就会报错。如果<>连写就是会被自动解析成" <> ",如果是<字段值>,就会报错"

从客户端(Description="")中检测到有潜在危险的 Request.Form 值。

"。