我正在做一个项目,但我不习惯 C#。我试图在我的旧工作代码之后工作。我找不到任何区别。
我的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);
}
}