duplicate form submission in mvc, without using javascript

77 views Asked by At

im working in a project where we are assigned with different forms to create. When im using the submit button to add a new record, its either duplicated or posted 3 times and i cant find the reason why. Using javascript with a simple function can solve the problem but i am told to not use javascript and just use the default type ="submit". i can give you the code to my controller and check what could possibly be wrong. Thank you in advance! This is the post method :

 [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();
                }
            }
        }
    }
0

There are 0 answers