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

[Solved] Incell editing not saving changes on string inputs

2 Answers 87 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.
German
Top achievements
Rank 1
German asked on 27 Apr 2012, 05:08 PM
Hi, I have a grid with inCell editing. I've made it pretty much similar to the example in your web, but for some reason, inputs that are strings don't retain their values after they lose focus (changes are reverted). Here's the code

@model IEnumerable<Ejecucion.Dominio.Entities.Partido>
 
@{
    ViewBag.Title = "Index";
}
 
<div class="formulario" style="width: 80%">
     
    <h2>Lista de partidos</h2>
 
    @{Html.Telerik().Grid(Model)
        .TableHtmlAttributes(new { style = "table-layout:fixed" })
        .Name("grillapartidos")
        .DataKeys(keys => keys.Add(av => av.Id))
 
        .ToolBar(commands => {
                    commands.Insert();
                    commands.SubmitChanges();
                    })
        .Columns(columns =>
        {
            columns.Bound(p => p.NombrePartido);
            columns.Bound(p => p.SeccionElectoral);
            columns.Bound(p => p.NombreIntendente);
            columns.Bound(p => p.CantidadHabitantes);
             
        })
        .KeyboardNavigation(kbd => kbd.EditOnTab(true))
       .DataBinding(dataBinding =>
            dataBinding.Ajax()
                .Select("_SelectBatchEditing", "Partidos")
                .Update("_SaveBatchEditing", "Partidos")
        )  
 
        .Editable(edit => edit.Mode(GridEditMode.InCell))
        .Render();
    }
</div>

and here's the controller
namespace Ejecucion.Controllers
{
    public class PartidosController : Controller
    {
        private IPartidosRepository db = new PartidosRepository();
 
        //
        // GET: /Partidos/
 
        public ViewResult Index()
        {
            return View(db.GetAll().ToList());
        }
 
        [GridAction]
        public ActionResult _SelectBatchEditing()
        {
            var partidos = db.GetAll();
            return View(new GridModel(partidos.ToList()));
        }
 
 
        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _SaveBatchEditing([Bind(Prefix = "inserted")]IEnumerable<Partido> insertedItems,
            [Bind(Prefix = "updated")]IEnumerable<Partido> updatedItems,
            [Bind(Prefix = "deleted")]IEnumerable<Partido> deletedItems)
        {
            if (insertedItems != null)
            {
                foreach (var item in insertedItems)
                {
                    db.Add(item);
                }
            }
            if (updatedItems != null)
            {
                foreach (var item in updatedItems)
                {
                    var target = db.Get(item.Id);
                    if (target != null)
                    {
                        target.NombrePartido = item.NombrePartido;
                        target.NombreIntendente = item.NombreIntendente;
                        target.CantidadHabitantes = item.CantidadHabitantes;
                        target.SeccionElectoral = item.SeccionElectoral;
                        db.Modify(target);
                    }
                }
            }
            if (deletedItems != null)
            {
                foreach (var item in deletedItems)
                {
                    db.Remove(item);
                }
            }
 
            var partidos = db.GetAll();
            return View(new GridModel(partidos.ToList()));
        }

as you can see, the code is almost equal yours in the samples, but for some reason, when I modify, for example, field NombrePartido (in english StateName), when I left the input, the value of it reverts to its original value. That behaviour doesn't happen on Integer o Decimal fields where changes are saved.

Thanks for your help and for this amazing product

2 Answers, 1 is accepted

Sort by
0
German
Top achievements
Rank 1
answered on 02 May 2012, 01:15 PM
Anyone?
0
German
Top achievements
Rank 1
answered on 02 May 2012, 02:04 PM
Ok, after a whole weekend trying to solve this I finally got it. It had to do with the editor helper for strings. For some reason (probably me) it had
@model string
 
@(Html.TextBox("",ViewData.TemplateInfo.FormattedModelValue,new { @class = "t-input"})
)

I've renamed String.cshtml to another name (foo.cshtml) and voila, it worked

Hope this helps someone else aswell

Thanks anyway
Tags
Grid
Asked by
German
Top achievements
Rank 1
Answers by
German
Top achievements
Rank 1
Share this question
or