私のプログラムはエラーなしでコンパイルされますが、残念ながらデータがデータベースに挿入されません。データベーステーブルは「Customers」と呼ばれます。ここで私が持っている私のモデルの私のコードは素晴らしいでしょう:
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>