0
我有一個ComicPanel
的編輯頁面,其中包含ComicPanelText
的列表。將子項添加到MVC父項的父項列表中編輯
我想添加一個新的ComicPanelText,所以我需要一個'添加'按鈕,但提交按鈕會轉到我的EditController。我怎樣才能添加一個新的提交按鈕來確定控制器中按下了哪個按鈕?
查看/共享/ EditorTemplates/ComicPanelText.cshtml
@model ComicNet.Models.ComicPanelText
<tr>
<td></td>
<td>
@Html.HiddenFor(x => x.ComicPanelTextId)
@Html.TextBoxFor(x => x.ComicText)
</td>
</tr>
查看/ ComicPanels/Edit.cshtml
@model ComicNet.Models.ComicPanel
@{
ViewBag.Title = "Edit";
}
<h2>Edit</h2>
<form action="" method="post" enctype="multipart/form-data">
@Html.AntiForgeryToken()
@Html.ValidationSummary(true);
<table>
<tr>
<td>
@Html.LabelFor(m => m.Name)
</td>
<td>
@Html.EditorFor(m => m.Name)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(m => m.PanelNumber)
</td>
<td>
@Html.EditorFor(m => m.PanelNumber)
</td>
</tr>
<tr>
<td></td>
<td>
<img src='@Html.DisplayFor(model => model.Url)' width="200" height="200" />
</td>
</tr>
<tr>
<td>
@Html.LabelFor(m => m.Width)
</td>
<td>
@Html.EditorFor(m => m.Width)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(m => m.Height)
</td>
<td>
@Html.EditorFor(m => m.Height)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(m => m.ImageUpload)
</td>
<td>
@Html.TextBoxFor(m => m.ImageUpload, new { type = "file" })
</td>
</tr>
@Html.EditorFor(x => x.ComicPanelTexts)
</table>
<div>
@Html.HiddenFor(m => m.FileName)
</div>
<div>
@Html.HiddenFor(m => m.ComicPanelId)
</div>
<button type="submit">Update</button>
</form>
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
ComicPanelsController.cs
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(ComicPanel comicPanel)
{
//...
}