我的程序没有错误编译,但遗憾的是它没有将数据插入数据库。数据库表称为“客户” 这里有任何帮助都很棒我的代码 在我的模型中我有:
public ActionResult Apply()
{
return View();
}
//
// POST: /Default1/Create
[HttpPost]
public ActionResult Apply(CUSTOMER customer)
{
if (ModelState.IsValid)
return View();
try
{
db.CUSTOMERs.Add(customer);
db.SaveChanges();
return RedirectToAction("Apply");
}
catch
{
return View();
}
}
然后在我的mvc我有:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<GreenEnergyGr.Models.CUSTOMER>" %>
应用
<form id="form1" runat="server">
<fieldset>
<legend>CUSTOMER</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.CustomerName) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.CustomerName) %>
<%: Html.ValidationMessageFor(model => model.CustomerName) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.CustomerSurname) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.CustomerSurname) %>
<%: Html.ValidationMessageFor(model => model.CustomerSurname) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.CustomerAddress) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.CustomerAddress) %>
<%: Html.ValidationMessageFor(model => model.CustomerAddress) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.CustomerLocation) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.CustomerLocation) %>
<%: Html.ValidationMessageFor(model => model.CustomerLocation) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.CustomerTelephone) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.CustomerTelephone) %>
<%: Html.ValidationMessageFor(model => model.CustomerTelephone) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.CustomerEmail) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.CustomerEmail) %>
<%: Html.ValidationMessageFor(model => model.CustomerEmail) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.CustomerPostCode) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.CustomerPostCode) %>
<%: Html.ValidationMessageFor(model => model.CustomerPostCode) %>
</div>
<p>
<input type="submit" value="Send" />
</p>
</fieldset>
答案 0 :(得分:0)
如果您的视图有效,那么您已经配置了您可能确实将数据保存到您正在查看的数据库中。如果您没有在正确的位置正确指定名称,则实体框架将提取名称。查看服务器上的其他数据库,看看是否有流氓。