views:

271

answers:

3

I have a Asp.net MVC web application, containing mostly text. I want to put a feature into it so that admin can easily edit text/html using the web. May be some double clicking on a page and converting it into editable and save able. How can i do it? any sample code?

I need this to be done for Asp.net MVC.

A: 

you will need to provide controller actions and corresponding Views for Edit operation. You can then restrict this action /operation only to Admin by using Security infrastructure provided by Asp.Net.

something similar

public ActionResult Edit(int id)
{
    var dataToEdit = (from c in _entities.ContactSet
                           where c.Id == id
                           select c).FirstOrDefault();

    return View(contactToEdit);
}

Have a look at this tutorial, will give an idea of how it works

Asad Butt
A: 

Use a jQuery Edit in Place plugin.

  • Make sure you have a database table with a row for each paragraph (could also be an XML file or some other means of storing structured data)
  • When rendering your pages, make each <p> has a class 'editable'
  • When the user requesting the page is an admin, do a

    $(document).ready(function() { $('p.editable').editable(...); });

  • When the admin edits text, submit it to an action like this:

    public JSONResult Edit(int id, string content){ /* Update content / / Return new text from database (in case something went wrong, the data won't have changed - you could return a JSON datastructure signaling an error */ return Json(newcontent); }

  • Insert the new content in the paragraph.

Rune
How to know which paragraph was edited???
coure06
If you are using the jEditable plugin I linked to above, the plug-in will send the id of the P to the server, so you just make sure it has an id from which you can determine the database id of the paragraph (maybe somethink like id="p_27" - in which case you should change "int id" in your action to "string id"). Have a look at the jEditable documentation, particularly the id option.
Rune
A: 

Check out my codeplex project @ http://editregion.codeplex.com/. It pretty much does what you describe and stores the content in xml files in the app_data folder and may be sufficient for your purposes.

ravi