我想通過ajax添加和刪除國家對象的本地化名稱。因此我已經構建了兩個部分視圖。第一個包含country-object的generel edit funcionality,第二個partial視圖(將在第一個視圖內呈現)包含添加/刪除本地化名稱的邏輯。首次提交Ajax Form作品,但第二次提交不做任何事
第一局部視圖:
@model CountryViewModel
// scripts here
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
[...] // the fields of the object to edit...
</fieldset>
}
// this tag will be updated by the partial view
<div id="localizedNamesOverview">
@Html.Partial("LocalizedNamesOverview",
Model.LocalizedNames,
new ViewDataDictionary
{
{ "countryId", Model.CountryId }
})
</div>
第二部分視圖:
@model IEnumerable<LocalizedNameViewModel>
<table>
@foreach (var item in Model)
{
<tr>
<td> @item.Language </td>
<td> @item.Name </td>
<td>
@Ajax.ActionLink("Delete",
"DeleteLocalizedName",
"Country",
new { countryId = this.ViewData[ "countryId" ],
localizedNameId = item.CountryI18nId },
new AjaxOptions
{
UpdateTargetId="localizedNamesOverview",
InsertionMode=InsertionMode.Replace,
HttpMethod="POST"
})
</td>
</tr>
}
@using(Ajax.BeginForm("AddLocalizedName",
"Country",
new { countryId = this.ViewData[ "countryId" ] },
new AjaxOptions
{
UpdateTargetId = "localizedNamesOverview",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST"
}))
{
<tr>
<td> <input class="text-box single-line" id="LanguageId" name="LanguageId" value="" type="text" /> </td>
<td> <input class="text-box single-line" id="Name" name="Name" value="" type="text" /> </td>
<td> <input type="submit" value="Add new localized name" /> </td>
</tr>
}
</table>
專用控制器返回時本地化名稱要麼添加或移除的第二局部視圖,並通過添加內容替換其本身從第一個視圖進入'localizedNamesOverview'。到目前爲止,這工作正如我所料。
現在的問題是這種行爲只有一次。如果我已成功添加或刪除名稱,則無法刪除/添加第二個名稱。目前我看不到問題出在哪裏,因爲生成的html看起來等於第一次提交之後。
任何幫助表示讚賞。
由於