我的程序编译没有错误,但不幸的是它没有将数据插入数据库。数据库表被称为“客户”任何帮助都会很棒这是我在我的模型中的代码:
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>