-4
我正在開發一個項目,但我不習慣C#。我試圖按照舊的工作代碼工作。我找不到任何區別。沒有無參數的構造函數爲這個對象定義,ID爲
我的HTML表單:
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.TicketID)
<fieldset>
<legend>Ticketdetail</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Anmerkung)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Anmerkung)
@Html.ValidationMessageFor(model => model.Anmerkung)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
行動:
public ActionResult CreateDetail(int id)
{
if (id == -1) return Index(-1);
return View(new cTicketDetail(id, User.Identity.Name));
}
[HttpPost]
public ActionResult CreateDetail(cTicketDetail collection)
{
//int TicketID = collection.TicketID;
try
{
if (ModelState.IsValid)
{
collection.Write();
}
return RedirectToAction("Details", collection.TicketID);
}
catch
{
return this.CreateDetail(collection.TicketID);
}
}
the error after commiting my Form
哇THX!我認爲這將是okey,因爲它就像公共cTicketDetail(INT ID = -1,字符串用戶名=「」),但現在它可以與一個額外的結構 – yellowsir