我有一个问题。我正在制作一张桌子,但是我需要一个添加页面,用户可以在其中填写文本框(或其他内容),然后按添加。如果发生这种情况,则需要使用用户添加的信息来更新表。
有人可以帮我吗?因为我不知道如何开始。
表格页面中的代码:
@model IEnumerable<DNDB.Models.Domeinnaam>
@Styles.Render("~/Content/StyleSheet.css")
@{
ViewBag.Title = "Index";
}
<h2>Domeinnaam Overzicht</h2>
@Html.ActionLink("add", "CreateDomeinnaam.cshtml")
<table id="tabledomeinnamen">
<tr>
<th>
@Html.DisplayNameFor(model => model.IsActief)
</th>
<th>
@Html.DisplayNameFor(model => model.Naam)
</th>
<th>
@Html.DisplayNameFor(model => model.TLD)
</th>
<th>
@Html.DisplayNameFor(model => model.DatumRegistratie)
</th>
<th>
@Html.DisplayNameFor(model => model.Omschrijving)
</th>
<th>
@Html.DisplayNameFor(model => model.DatumOpzeg)
</th>
<th>
@Html.DisplayNameFor(model => model.EigenaarID)
</th>
<th>
@Html.DisplayNameFor(model => model.Opmerking)
</th>
<th>
@Html.DisplayNameFor(model => model.BeheerAccountID)
</th>
<th>
@Html.DisplayNameFor(model => model.KlantID)
</th>
<th>
@Html.DisplayNameFor(model => model.RegistrarID)
</th>
<th>
@Html.DisplayNameFor(model => model.BetaaldVan)
</th>
<th>
@Html.DisplayNameFor(model => model.BetaaldTot)
</th>
<th>
@Html.DisplayNameFor(model => model.AfspraakPrijs)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.IsActief)
</td>
<td>
@Html.DisplayFor(modelItem => item.Naam)
</td>
<td>
@Html.DisplayFor(modelItem => item.TLD)
</td>
<td>
@Html.DisplayFor(modelItem => item.DatumRegistratie)
</td>
<td>
@Html.DisplayFor(modelItem => item.Omschrijving)
</td>
<td>
@Html.DisplayFor(modelItem => item.DatumOpzeg)
</td>
<td>
@Html.DisplayFor(modelItem => item.EigenaarID)
</td>
<td>
@Html.DisplayFor(modelItem => item.Opmerking)
</td>
<td>
@Html.DisplayFor(modelItem => item.BeheerAccountID)
</td>
<td>
@Html.DisplayFor(modelItem => item.KlantID)
</td>
<td>
@Html.DisplayFor(modelItem => item.RegistrarID)
</td>
<td>
@Html.DisplayFor(modelItem => item.BetaaldVan)
</td>
<td>
@Html.DisplayFor(modelItem => item.BetaaldTot)
</td>
<td>
@Html.DisplayFor(modelItem => item.AfspraakPrijs)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ID })
@Html.ActionLink("Details", "Details", new { id=item.ID })
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
</td>
</tr>
}
</table>
表格页面中的代码:
@Html.ActionLink("add", "CreateDomainName", "Domain") //Second parameter is the action name, Third parameter is the controller name. If your 'list'(table) page action and 'add' action are in the same controller then this field is optional.
控制器中的CreateDomainName操作。
public ActionResult CreateDomainName()
{
return View();
}
[HttpPost]
public ActionResult CreateDomainName(Domeinnaam model)
{
if(ModelState.IsValid)
{
//Your code to save
}
return RedirectToAction("Index");
}
要生成CreateDomainName操作的视图,请右键单击操作,然后单击“添加视图”。
CreateDomainName操作的视图。
@using(Html.BeginForm())
{
<!-- Your html code -->
<input type="submit">Add</input>
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句