我正在使用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