0
我正在製作一個露營程序。客戶可以在網站上預訂,接待員可以接受並在客戶到達時向客戶添加更多信息(如護照號碼)。填寫多表格一個MVC C#
我的預約表看起來是這樣的:
[ID] INT IDENTITY (1, 1) NOT NULL,
[StartDatum] DATE NULL,
[EindDatum] DATE NULL,
[Plaats] VARCHAR (50) NULL,
[Status] VARCHAR (50) NULL,
[KlantID] INT NULL,
CONSTRAINT [FK_Reserveringen_ToTable] FOREIGN KEY ([KlantID]) REFERENCES [dbo].[Klants] ([Id])
而我的客戶表看起來像這樣:
[Id] INT IDENTITY (1, 1) NOT NULL,
[Voornaam] VARCHAR (50) NOT NULL,
[Achternaam] VARCHAR (50) NOT NULL,
[Adres] VARCHAR (50) NOT NULL,
[Postcode] VARCHAR (50) NULL,
[Plaats] VARCHAR (50) NULL,
[Telefoon] INT NOT NULL,
[Geboortedatum] INT NULL,
[Documentnr] INT NULL,
[Verificatiemiddel] VARCHAR (50) NULL,
[Emailadres] VARCHAR (50) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
我有一個做customer表和保留表的典範。
這是我的看法怎麼看起來像預訂的網站
@model Camping.Domain.Entities.Reservering
<div class="panel panel-success">
<div class="panel-heading text-center"><h4>RSVP</h4></div>
<div class="panel-body">
@using (Html.BeginForm("KlantToevoegen", "Klant", FormMethod.Post, new { enctype = "mulipart/formdata" }))
{
@Html.ValidationSummary()
<div class="form-group">
<label>Voornaam:</label>
@Html.TextBoxFor(x => x.Voornaam, new { @class = "form-control" })
</div>
<div class="form-group">
<label>Achternaam:</label>
@Html.TextBoxFor(x => x.Achternaam, new { @class = "form-control" })
</div>
<div class="form-group">
<label>Emailadres:</label>
@Html.TextBoxFor(x => x.Emailadres, new { @class = "form-control" })
</div>
<div class="form-group">
<label>Telefoonnummer:</label>
@Html.TextBoxFor(x => x.Telefoonnnummer, new { @class = "form-control" })
</div>
<div class="form-group">
<label>Datum aankomst:</label>
@Html.TextBoxFor(x => x.StartDatum, new { @class = "form-control" })
</div>
<div class="form-group">
<label>Datum vertrek:</label>
@Html.TextBoxFor(x => x.EindDatum, new { @class = "form-control" })
</div>
<div class="form-group">
<label>Plaats:</label>
@Html.TextBoxFor(x => x.Plaats, new { @class = "form-control" })
</div>
<div class="text-center">
<input class="btn btn-success" type="submit" value="Klant toevoegen" />
</div>
}
</div>
</div>
這種觀點我做了一個模型上。那就是:
namespace Camping.Domain.Entities
{
public class Reservering
{
public string Voornaam { get; set; }
public string Achternaam { get; set; }
public int Telefoonnnummer { get; set; }
public string Emailadres { get; set; }
public string Plaats { get; set; }
public DateTime StartDatum { get; set; }
public DateTime EindDatum { get; set; }
}
}
而且控制器類:
using Camping.Domain.Abstract;
using Camping.Domain.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Camping.WebUII.Controllers
{
public class ReserveringController : Controller
{
private IRepository repository;
public ReserveringController(IRepository iRepository)
{
this.repository = iRepository;
}
[HttpGet]
public ViewResult ReserveringAanmaken()
{
return View();
}
[HttpPost]
public ActionResult Add(Reservering model)
{
var klant = new Klant
{
Voornaam = model.Voornaam,
Achternaam = model.Achternaam,
Emailadres = model.Emailadres,
Telefoon = model.Telefoonnnummer
};
var reservering = new Reserveringen
{
StartDatum = model.StartDatum,
EindDatum = model.EindDatum,
Plaats = model.Plaats
};
repository.KlantToevoegen(klant);
repository.ReserveringToevoegen(reservering);
return View();
}
}
}
這個解決方案沒有工作,出於某種原因,感覺不對我在做什麼。任何人都可以將我指向正確的方向嗎?瞭解更多信息。隨意問:)
當我通過視圖添加日期。我只填寫客戶表,而不是預訂表。
它是如何不工作,完全? – vorou
我收到一個錯誤:在EntityFramework.dll中發生了類型爲「System.Data.Entity.Infrastructure.DbUpdateException」的異常,但未在用戶代碼中處理 附加信息:更新條目時發生錯誤。詳情請參閱內部例外。 內部例外?我似乎無法找到它們。 但是我覺得你在正確的軌道上? – valheru
用調試器運行它,等待發生異常。您將能夠看到異常詳細信息,其中會有'InnerException'屬性。在那裏你會找到更有幫助的描述。 – vorou