This is a migrated thread and some comments may be shown as answers.

[Solved] New record is always added on the end

0 Answers 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marcin
Top achievements
Rank 1
Marcin asked on 02 Aug 2011, 09:50 AM
Hi i hava a problem. I user grid with inline edit. When i add new record he is added correctly to db but after i return my grid view model my new added item is always on the end:/. After i reload page my new item is on correct place using rules to sort.
public ActionResult _AjaxCreateCities(int VoivodeshipName)
       {
           CityModel cm = new CityModel();
           if (TryUpdateModel(cm))
           {
               cm.VoivodeshipId = VoivodeshipName;
               if (configurationService.CheckIfCityIsUnique(GetCityItemFromCityModelToUpdate(cm,cm.VoivodeshipId)))
               {
                   configurationService.InsertCity(GetCityItemFromCityModelToUpdate(cm, cm.VoivodeshipId));
               }
               else
               {
                   ModelState.AddModelError("", App_GlobalResources.I18n.CITY_NOT_UNIQUE);
                   Response.StatusCode = 500;
                   return Content(String.Join(" ", (from state in ModelState select state).SelectMany(s => s.Value.Errors).Select(e => e.ErrorMessage).ToArray()));
               }
 
           }
           return View(new GridModel(GetAllCities()));
       }

private IList<CityModel> GetAllCities()
     {
         IList<CityItem> cities = configurationService.GetAllCities();
         IList<CityModel> citiesModels = new List<CityModel>();
         foreach (CityItem item in cities)
         {
             citiesModels.Add(GetCityModelFromCityItem(item));
         }
         citiesModels=citiesModels.OrderBy(city => city.CityName).ToList();
         return citiesModels;
     }

So like you see i always sort my list. And this sort works correctly - after add new item my item is on correct position. But on view i see in bad position
Tags
Grid
Asked by
Marcin
Top achievements
Rank 1
Share this question
or