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

[Solved] Binding problems with EditorFor

3 Answers 241 Views
Editor
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Roberto
Top achievements
Rank 1
Roberto asked on 16 Nov 2010, 08:21 PM
I'm having some problems with binding.
When I use "EditorFor" for a field appears that is not held binding.

 
<%: Html.TextBoxFor (e => e.ModelObject.TextoRodape)%>
renders and displays correctly. In the post method, the value is correct.
<%: Html.Telerik (). EditorFor (e => e.ModelObject.TextoCorpo)%>
renders and displays correctly. In the post method, the value is a null string.

Model:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla.Web.Mvc;
using Documentos.Lib;
 
namespace Documentos.Models
{
    public class OficioModeloViewModel : ViewModelBase<OficioModelo>
    {
        public Guid OficioModeloId
        {
            get { return ModelObject.Id; }
            set { ModelObject.Id = value; }
        }
 
        // OficioModelo is an CSLA object and resides on another project
        //default
        public OficioModeloViewModel()
        {
            ModelObject = OficioModelo.NewOficioModelo();
        }
 
        //convenience
        public OficioModeloViewModel(Guid id)
        {
            ModelObject = OficioModelo.GetOficioModelo(id);
        }
 
    }
}

View
<%@ Page Title=""
Language="C#"
MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<Documentos.Models.OficioModeloViewModel>" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Edit
</asp:Content>
 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
 
    <h2>Edit</h2>
 
    <% using (Html.BeginForm()) {%>
        <%: Html.ValidationSummary(true) %>
         
        <fieldset>
             
 
 
 
            <%:
                Html.Telerik().EditorFor(e => e.ModelObject.TextoCabecalho)
                .HtmlAttributes(new { style = "height:200px" })
                %>
 
 
            <%:Html.Telerik().EditorFor(e => e.ModelObject.TextoCorpo)%>
 
            <%:Html.TextBoxFor(e => e.ModelObject.TextoRodape)%>
 
            <p>
                <input type="submit" value="Save" />
            </p>
        </fieldset>
 
    <% } %>
 
    <div>
        <%: Html.ActionLink("Back to List", "Index") %>
    </div>
 
</asp:Content>

Control
...
//
// GET: /OficioModelo/Edit/5
   public ActionResult Edit(Guid id)
   {
        ViewData.Model = new OficioModeloViewModel(id);
        return View();
   }
//
// POST: /OficioModelo/Edit/5
   [HttpPost]
   public ActionResult Edit(Guid id, OficioModeloViewModel oficioModeloViewModel)
   {
       
      // when I use TextBoxFor, oficioModeloViewModel returns a filled object,
      // but when I use EditorFor, an empty object is returned...
      oficioModeloViewModel.OficioModeloId = id;
 
      if (SaveObject<OficioModelo>(oficioModeloViewModel.ModelObject, true))
         return RedirectToAction("Index");
 
      ViewData.Model = oficioModeloViewModel;
      return View();
   }
...

Is there any way to perform the bind by hand?

Regards,
Roberto

3 Answers, 1 is accepted

Sort by
0
Hristo Germanov
Telerik team
answered on 17 Nov 2010, 08:50 AM
Hi Roberto,

Attached is a sample project reproducing your issue and there is no such problem. Could you please examine it and modified to reproduce your issues so I will be able to better assist you?

All the best,
Hristo Germanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Roberto
Top achievements
Rank 1
answered on 17 Nov 2010, 12:51 PM
Hi, Hristo.

Thank you for your attention.
I updated yesterday to version Q3 and the problem was solved.

Just one more question: How to insert images from the local disk? It is possible in Q3?


Regards,
Roberto
0
Accepted
Hristo Germanov
Telerik team
answered on 17 Nov 2010, 03:07 PM
Hello Roberto,

Unfortunately this feature isn't finished yet. You can cast your vote for it here.

Sincerely yours,
Hristo Germanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Editor
Asked by
Roberto
Top achievements
Rank 1
Answers by
Hristo Germanov
Telerik team
Roberto
Top achievements
Rank 1
Share this question
or