我按照模型文章创建视图。
class Article
{
public string Title {get;set;}
public List<string> Terms {get;set}
}
条款 - 可以是任何计数,我希望它们可以逐渐添加
@using (Html.BeginForm("Create"))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>CreateArticle</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Title)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
</div>
<div class="editor-label">
Terms:
</div>
<div id="divList">
</div>
@using (Ajax.BeginForm("Update", new AjaxOptions() { Confirm = "Add", HttpMethod = "Post", UpdateTargetId = "divList", InsertionMode = InsertionMode.InsertAfter }))
{
@Html.Partial("_TermPP", "")
<input id="count" name="count" type="hidden" value="-1" />
<input type="submit" value="add" onclick="javascript:plus()" />
}
</fieldset>
}
_TermPP:
@model String
<div>
<input type="text" name="terms[@(ViewBag.Count==null?0:ViewBag.Count)]" value="@(Model == null ? "" : Model)" /> </div>
当点击发送到ADD形式但我需要在更新上创建。这是怎么回事?