Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无数据库的ASP.NET MVC_C#_Asp.net Mvc - Fatal编程技术网

C# 无数据库的ASP.NET MVC

C# 无数据库的ASP.NET MVC,c#,asp.net-mvc,C#,Asp.net Mvc,我正在尝试在MVC上创建一个没有数据库的完整CRUD应用程序。我使用模板视图创建者来“创建/详细信息/编辑/删除…”我在保存/编辑/删除时遇到问题,因为大多数联机资源都是在数据库/框架之外工作的。对于“创建”,在所有字段中输入后,它会将我带回到所有PersonModel的“列表”页面,而不带新输入的PersonModel。我无法让[HttpPost]进行编辑 using MVCDemo.Models; using System; using System.Collections.Generic;

我正在尝试在MVC上创建一个没有数据库的完整CRUD应用程序。我使用模板视图创建者来“创建/详细信息/编辑/删除…”我在保存/编辑/删除时遇到问题,因为大多数联机资源都是在数据库/框架之外工作的。对于“创建”,在所有字段中输入后,它会将我带回到所有PersonModel的“列表”页面,而不带新输入的PersonModel。我无法让[HttpPost]进行编辑

using MVCDemo.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVCDemo.Controllers
{
    public class PersonController : Controller
    {
        List<PersonModel> people = new List<PersonModel>()
        {
               new PersonModel { First = "DAD", Last = "Nguyen", Name = "Study", About = "Study for test", Done = false, Id = 1 },
               new PersonModel { First = "David", Last = "Smith", Name = "Grocery", About = "Buy apple and bananana", Done = true , Id = 2},
               new PersonModel { First = "Tom", Last = "Davidson", Name = "Fix car", About = "Headlight and mirror is broken", Done = false, Id = 3 },
               new PersonModel { First = "Maddie", Last = "Madison", Name = "Job application", About = "Follow up on job interview ", Done = false , Id = 4}
        };

        // GET: Person
        public ActionResult Index()
        {
            return View(people);
        }
        [HttpGet]
        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(PersonModel per)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return View("Create", per);
                }
                people.Add(per);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        public ActionResult Details(int id)
        {
            PersonModel per = people.Find(emp => emp.Id == id);
            return View(per);
        }

        [HttpGet]
        public ActionResult Edit(int id)
        {
            PersonModel per = people.Find(emp => emp.Id == id);
            return View(per);
        }

        public ActionResult Delete()
        {
            return View();
        }


    }
}
索引cshtml

public class PersonModel
   {
       public int Id { get; set; }
       public string First { get; set; }
       public string Last { get; set; }
       public bool Done { get; set; } 

       public string Name { get; set; }
       public string About { get; set; }

   }
@model IEnumerable<MVCDemo.Models.PersonModel>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.First)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Last)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Done)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.About)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.First)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Last)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Done)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.About)
        </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>
@model MVCDemo.Models.PersonModel

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>

@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>PersonModel</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.First, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.First, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.First, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Last, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Last, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Last, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Done, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                <div class="checkbox">
                    @Html.EditorFor(model => model.Done)
                    @Html.ValidationMessageFor(model => model.Done, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.About, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.About, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.About, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
@model MVCDemo.Models.PersonModel

@{
    ViewBag.Title = "Details";
}

<h2>Details</h2>

<div>
    <h4>PersonModel</h4>
    <hr />
    <dl class="dl-horizontal">
        <dt>
            @Html.DisplayNameFor(model => model.First)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.First)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Last)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Last)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Done)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Done)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Name)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Name)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.About)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.About)
        </dd>

    </dl>
</div>
<p>
    @Html.ActionLink("Edit", "Edit", new { id = Model.Id }) |
    @Html.ActionLink("Back to List", "Index")
</p>
@model MVCDemo.Models.PersonModel

@{
    ViewBag.Title = "Edit";
}

<h2>Edit</h2>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>PersonModel</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.Id)

        <div class="form-group">
            @Html.LabelFor(model => model.First, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.First, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.First, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Last, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Last, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Last, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Done, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                <div class="checkbox">
                    @Html.EditorFor(model => model.Done)
                    @Html.ValidationMessageFor(model => model.Done, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.About, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.About, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.About, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Save" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
@model IEnumerable
@{
ViewBag.Title=“Index”;
}
指数

@ActionLink(“新建”、“创建”)

@DisplayNameFor(model=>model.First) @DisplayNameFor(model=>model.Last) @DisplayNameFor(model=>model.Done) @DisplayNameFor(model=>model.Name) @DisplayNameFor(model=>model.About) @foreach(模型中的var项目){ @DisplayFor(modelItem=>item.First) @DisplayFor(modeleItem=>item.Last) @DisplayFor(modelItem=>item.Done) @DisplayFor(modelItem=>item.Name) @DisplayFor(modeleItem=>item.About) @ActionLink(“编辑”,“编辑”,新的{id=item.id})| @ActionLink(“详细信息”,“详细信息”,新的{id=item.id})| @ActionLink(“删除”,“删除”,新的{id=item.id}) }
创建cshtml

public class PersonModel
   {
       public int Id { get; set; }
       public string First { get; set; }
       public string Last { get; set; }
       public bool Done { get; set; } 

       public string Name { get; set; }
       public string About { get; set; }

   }
@model IEnumerable<MVCDemo.Models.PersonModel>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.First)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Last)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Done)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.About)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.First)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Last)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Done)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.About)
        </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>
@model MVCDemo.Models.PersonModel

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>

@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>PersonModel</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.First, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.First, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.First, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Last, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Last, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Last, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Done, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                <div class="checkbox">
                    @Html.EditorFor(model => model.Done)
                    @Html.ValidationMessageFor(model => model.Done, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.About, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.About, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.About, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
@model MVCDemo.Models.PersonModel

@{
    ViewBag.Title = "Details";
}

<h2>Details</h2>

<div>
    <h4>PersonModel</h4>
    <hr />
    <dl class="dl-horizontal">
        <dt>
            @Html.DisplayNameFor(model => model.First)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.First)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Last)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Last)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Done)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Done)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Name)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Name)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.About)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.About)
        </dd>

    </dl>
</div>
<p>
    @Html.ActionLink("Edit", "Edit", new { id = Model.Id }) |
    @Html.ActionLink("Back to List", "Index")
</p>
@model MVCDemo.Models.PersonModel

@{
    ViewBag.Title = "Edit";
}

<h2>Edit</h2>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>PersonModel</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.Id)

        <div class="form-group">
            @Html.LabelFor(model => model.First, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.First, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.First, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Last, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Last, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Last, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Done, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                <div class="checkbox">
                    @Html.EditorFor(model => model.Done)
                    @Html.ValidationMessageFor(model => model.Done, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.About, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.About, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.About, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Save" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
@model MVCDemo.Models.PersonModel
@{
ViewBag.Title=“创建”;
}
创造
@使用(Html.BeginForm())
{
@Html.AntiForgeryToken()
个人模型

@Html.ValidationSummary(true,“,new{@class=“text danger”}) @LabelFor(model=>model.First,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.First,new{htmlAttributes=new{@class=“formcontrol”}) @Html.ValidationMessageFor(model=>model.First,“,new{@class=“text danger”}) @LabelFor(model=>model.Last,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.Last,new{htmlAttributes=new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.Last,“,new{@class=“text danger”}) @LabelFor(model=>model.Done,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.Done) @Html.ValidationMessageFor(model=>model.Done,“,new{@class=“text danger”}) @LabelFor(model=>model.Name,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.Name,new{htmlAttributes=new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.Name,“,new{@class=“text danger”}) @LabelFor(model=>model.About,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.About,new{htmlAttributes=new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.About,“,new{@class=“text danger”}) } @ActionLink(“返回列表”、“索引”)
详细信息cshtml

public class PersonModel
   {
       public int Id { get; set; }
       public string First { get; set; }
       public string Last { get; set; }
       public bool Done { get; set; } 

       public string Name { get; set; }
       public string About { get; set; }

   }
@model IEnumerable<MVCDemo.Models.PersonModel>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.First)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Last)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Done)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.About)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.First)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Last)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Done)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.About)
        </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>
@model MVCDemo.Models.PersonModel

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>

@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>PersonModel</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.First, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.First, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.First, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Last, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Last, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Last, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Done, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                <div class="checkbox">
                    @Html.EditorFor(model => model.Done)
                    @Html.ValidationMessageFor(model => model.Done, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.About, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.About, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.About, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
@model MVCDemo.Models.PersonModel

@{
    ViewBag.Title = "Details";
}

<h2>Details</h2>

<div>
    <h4>PersonModel</h4>
    <hr />
    <dl class="dl-horizontal">
        <dt>
            @Html.DisplayNameFor(model => model.First)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.First)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Last)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Last)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Done)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Done)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Name)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Name)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.About)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.About)
        </dd>

    </dl>
</div>
<p>
    @Html.ActionLink("Edit", "Edit", new { id = Model.Id }) |
    @Html.ActionLink("Back to List", "Index")
</p>
@model MVCDemo.Models.PersonModel

@{
    ViewBag.Title = "Edit";
}

<h2>Edit</h2>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>PersonModel</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.Id)

        <div class="form-group">
            @Html.LabelFor(model => model.First, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.First, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.First, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Last, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Last, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Last, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Done, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                <div class="checkbox">
                    @Html.EditorFor(model => model.Done)
                    @Html.ValidationMessageFor(model => model.Done, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.About, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.About, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.About, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Save" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
@model MVCDemo.Models.PersonModel
@{
ViewBag.Title=“详细信息”;
}
细节
个人模型

@DisplayNameFor(model=>model.First) @DisplayFor(model=>model.First) @DisplayNameFor(model=>model.Last) @DisplayFor(model=>model.Last) @DisplayNameFor(model=>model.Done) @DisplayFor(model=>model.Done) @DisplayNameFor(model=>model.Name) @DisplayFor(model=>model.Name) @DisplayNameFor(model=>model.About) @DisplayFor(model=>model.About) @ActionLink(“编辑”,“编辑”,新的{id=Model.id})| @ActionLink(“返回列表”、“索引”)

编辑cshtml

public class PersonModel
   {
       public int Id { get; set; }
       public string First { get; set; }
       public string Last { get; set; }
       public bool Done { get; set; } 

       public string Name { get; set; }
       public string About { get; set; }

   }
@model IEnumerable<MVCDemo.Models.PersonModel>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.First)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Last)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Done)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.About)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.First)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Last)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Done)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.About)
        </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>
@model MVCDemo.Models.PersonModel

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>

@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>PersonModel</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.First, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.First, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.First, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Last, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Last, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Last, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Done, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                <div class="checkbox">
                    @Html.EditorFor(model => model.Done)
                    @Html.ValidationMessageFor(model => model.Done, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.About, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.About, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.About, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
@model MVCDemo.Models.PersonModel

@{
    ViewBag.Title = "Details";
}

<h2>Details</h2>

<div>
    <h4>PersonModel</h4>
    <hr />
    <dl class="dl-horizontal">
        <dt>
            @Html.DisplayNameFor(model => model.First)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.First)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Last)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Last)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Done)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Done)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.Name)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Name)
        </dd>

        <dt>
            @Html.DisplayNameFor(model => model.About)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.About)
        </dd>

    </dl>
</div>
<p>
    @Html.ActionLink("Edit", "Edit", new { id = Model.Id }) |
    @Html.ActionLink("Back to List", "Index")
</p>
@model MVCDemo.Models.PersonModel

@{
    ViewBag.Title = "Edit";
}

<h2>Edit</h2>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>PersonModel</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.Id)

        <div class="form-group">
            @Html.LabelFor(model => model.First, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.First, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.First, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Last, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Last, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Last, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Done, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                <div class="checkbox">
                    @Html.EditorFor(model => model.Done)
                    @Html.ValidationMessageFor(model => model.Done, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.About, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.About, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.About, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Save" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
@model MVCDemo.Models.PersonModel
@{
ViewBag.Title=“编辑”;
}
编辑
@使用(Html.BeginForm())
{
@Html.AntiForgeryToken()
个人模型

@Html.ValidationSummary(true,“,new{@class=“text danger”}) @Html.HiddenFor(model=>model.Id) @LabelFor(model=>model.First,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.First,new{htmlAttributes=new{@class=“formcontrol”}) @Html.ValidationMessageFor(model=>model.First,“,new{@class=“text danger”}) @LabelFor(model=>model.Last,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.Last,new{htmlAttributes=new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.Last,“,new{@class=“text danger”}) @LabelFor(model=>model.D