0

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

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>
4

1 回答 1

0

如果您的视图是有效的,那么您已经配置了您可能确实将数据保存到了您正在查看的数据库中。如果你没有在正确的地方正确地指定名称,实体框架会提取一个名称。查看服务器上的其他数据库,看看是否有流氓。

于 2013-04-20T02:34:10.467 回答