Search code examples
javascriptasp.net-mvc-3formsjquerylive

Form Post Preview On the fly using .net mvc 3 like in stackoverflow


I want to develop a live preview of form post similar to stackoverflow. I am using .net mvc 3.

I need some help to do that.

Thanks Yohan


Solution

  • At the highest level:

    1. Set a listener on the text area to wait for keyup events.
    2. When a key event is triggered, have a callback re-parse the text in the box.

    So, StackOverflow uses markdown or some variant thereof. The quickest way would be to have a client side markdown parser such as http://www.showdown.im/ ( Source code is offline at the moment so : https://github.com/coreyti/showdown ).

    Another way would be to have a preview button which passes the text in the box to the server which does the parsing, and passes back a reformatted result which the user can check to then submit. Not as quick and direct as the client side option, but saves loading a big chunk of javascript.