我在一个项目中工作,我们被分配了不同的表单来创建。当我使用提交按钮添加新记录时,它要么重复要么发布了 3 次,我找不到原因。使用带有简单函数的 javascript 可以解决问题,但我被告知不要使用 javascript,只需使用默认类型 =“submit”。我可以将代码提供给我的控制器并检查可能出现的问题。先感谢您!这是发布方法:
[HttpPost]
public ActionResult Edit(int countryId, FmCountry fmCountryToPost)
{
ViewData.Model = fmCountryToPost;
LoadProperty(fmCountryToPost, FmCountry._countryIdProperty, countryId);
if (fmCountryToPost.BrokenRulesCollection.Count > 0)
{
ViewData.ModelState.Clear();
ViewData.ModelState.AddRange(GeneralFunctions.AddObjectBrokenRulesToModelState(fmCountryToPost.BrokenRulesCollection));
Log.Info("Gabim me editimin e qytetit, kontrolli i BrokenRules" + fmCountryToPost.BrokenRulesCollection);
return PartialView();
}
else
{
if (countryId == 0)
{
if (SaveObject(fmCountryToPost, false))
{
Log.Info("Shteti u shtua me sukses. Parametra: countryId=" + countryId);
return RedirectToAction("Index", new { succesMessage = "Shteti u shtua me sukses" });
}
else
{
ViewData.ModelState.Clear();
Log.Info("Ka Ndodhur nje gabim ne shtimin e Shtetit. Parametra: countryId=" + countryId);
ViewData.ModelState.AddModelError("", Resources.Resource.CONTROLLER_ERROR);
return PartialView();
}
}
else
{
if (SaveObject(fmCountryToPost, true))
{
Log.Info("Shteti u editua me sukses. Parametra: countryId=" + countryId);
return RedirectToAction("Index", new { successMessage = "Shteti u modifikua me sukses" });
}
else
{
ViewData.ModelState.Clear();
Log.Info("Ka Ndodhur nje gabim ne editimin e Shtetit. Parametra: countryId=" + countryId);
ViewData.ModelState.AddModelError("", Resources.Resource.CONTROLLER_ERROR);
return PartialView();
}
}
}
}