【发布时间】:2011-06-02 02:01:28
【问题描述】:
我正在使用 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 引擎不支持此文件版本" 将我们作为第一个结果将我们带到解决方案:*.com/questions/4070860/…
标签: c# .net database asp.net-mvc-3