我正在使用mvc3在.net 4.0中设计一个项目。我使用了两个属性name
和fname
(父名)。数据存储在哪里?
我的控制器类:
loginController.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcMovie.Models;
namespace MvcMovie.Controllers
{
public class loginController : Controller
{
private logindata db = new logindata();
//
// GET: /login/
public ViewResult Index()
{
return View(db.loginobj.ToList());
}
//
// GET: /login/Details/5
public ViewResult Details(int id)
{
// login login = db.loginobj.Find(id);
login login = db.loginobj.Find(2) ;
return View(login);
}
//
// GET: /login/Create
public ActionResult Create()
{
return View();
}
//
// POST: /login/Create
[HttpPost]
public ActionResult Create(login login)
{
if (ModelState.IsValid)
{
db.loginobj.Add(login);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(login);
}
//
// GET: /login/Edit/5
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
}
}
模型类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
login.cs
namespace MvcMovie.Models
{
public class login
{
public int ID { get; set; }
public string name{get; set;}
public string fname { get; set; }
}
public class logindata : DbContext
{
public DbSet<login> loginobj { get; set; }
}
}
view.cshtml
@model IEnumerable<MvcMovie.Models.login>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
name
</th>
<th>
fname
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.name)
</td>
<td>
@Html.DisplayFor(modelItem => item.fname)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
@Html.ActionLink("Details", "Details", new { id=item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
</td>
</tr>
}
</table>
我想问的是其中存储的数据这是由我创建?意味着我如何看到由我完成的条目表?
只要我点击.sdf文件,然后出现如下图所示的问题,我该如何解决这个问题。我应该安装一些东西。我安装了Visual Studio 2010和SQL Server 2008
Pushpendra - 无需三倍复制相同的注释:)一个简单的谷歌搜索“这不是一个有效的SQL Server Compact数据库文件或文件版本不受当前SQL Server Compact Engine支持“作为_very first_结果将我们带入解决方案:http://stackoverflow.com/questions/4070860/sql-compact-4-0-cant-open-read-sdf -file – 2011-06-02 05:41:35