views:

21

answers:

2

Hi,

I am trying to use Jeditables (http://www.appelsiini.net/projects/jeditable) in my first castle monorail mvc application

I managed to have the textbox appearing and to the the ajax call, my problem is now that after the ajax call the edited text returs is not changes and i can t get the response after the call

this is my page

<head>
 <link href="../../Styles/Main.css" rel="stylesheet" type="text/css" />
    <script src="../../JavaScript/jQuery1.4.2.js" type="text/javascript"></script>
    <script src="../../JavaScript/EditInLine.js" type="text/javascript"></script>

 <script type="text/javascript">
  $(document).ready(function() {
   $('.editable').editable('/Home/Save', { 
        id        : 'editableId',
           name    : 'editableText',
     type      : 'textarea',
     cancel    : 'Cancel',
     submit    : 'OK',
     indicator : '<img src="img/indicator.gif">',
     tooltip   : 'Click to edit...',
     width     : '200',
     style     : 'display: inline',
     callbac   : function(value, settings) {
        alert(value);  
      return value;
    }

    });
  });
 </script>

</head>
<body>    


<label id='1' class='editable '>Some text</label>


</body>
</html>

and this my controller

using Castle.MonoRail.Framework;
using System;
using EditInLine.Model.Interfaces;
using EditInLine.Model;

namespace EditInLine.Controllers
{
    [Layout("Default"), Rescue("Default")]
    public class HomeController : SmartDispatcherController
    {
        private EditableElement editableElement;
        private EditableElement EditableElement
        {
            get
            {
                if (Session["EditableElement"] == null)
                {
                    Session["EditableElement"] = new EditableElement { Id = 1, Text = "Some text", CssClass = "editable" };
                }
                return (EditableElement)Session["EditableElement"];
            }            
        }


        public void Index()
        {
            PropertyBag["IsAdmin"] = true;
            PropertyBag["element"] = EditableElement;
        }

        public void Save()
        {
            var elementId = Convert.ToInt32(Request.Form["editableId"]);
            var text = Request.Form["editableText"];  

            var element = new EditableElement { Id = elementId, CssClass = "editable", Text = text };

            Session["EditableElement"] = element;            

        }


    }
}

thanks for you help

A: 

I found the solution

public void Save()
        {
            var elementId = Convert.ToInt32(Request.Form["editableId"]);
            var text = Request.Form["editableText"];  

            var element = new EditableElement { Id = elementId, CssClass = "editable", Text = text };

            Session["EditableElement"] = element;            

 Response.Write(text);
 CancelView();
        }
you can make your life easier by using parameter binding. The `Save()` method could look like this:
Ken Egozi
`public void Save(int editableId, string editableText) { Session["EditableElement"] = new EditableElement ...}`
Ken Egozi
and switch the `Response.Write` with `RenderText` which cancels the view
Ken Egozi
I'll post it as an answer to get proper syntax highlighting
Ken Egozi
+1  A: 

The problem with Save() was that you did not return a string to the browser. Easily fixed with RenderText() call. You should also be using parameter binding instead of messing with Request.Form:

public void Save(int editableId, string editableText)
{
    var element = new EditableElement { Id = editableId, CssClass = "editable", Text = editableText};

    Session["EditableElement"] = element;

    RenderText(editableText);
}
Ken Egozi