3

I have a following view model and it will be used to get Issue Description and Steps to recreate issue.

public class IssueViewModel
{
   public string IssueDesc { get; set; }
   public string ReCreationSteps  { get; set; }
}

View

@using (Html.BeginForm())
{
  @Html.LabelFor(model => model.IssueDescription)   
  @Html.TextAreaFor(m=>m.IssueDescription)
  @Html.LabelFor(model => model.ReCreationSteps )   
     <div class="editable" id="ReCreationSteps " name="ReCreationSteps" contenteditable="true">
        <ol>
          <li></li>
        </ol>
     </div>
  <input value="Create" type="submit" />
}

Controller

[HttpPost]
public ActionResult Create(IssueViewModel model)
{
   string html = model.Recreation;
   //<ol><li>Step:1 Enter the text</li><li>Step:2 Click the button <li></ol>
   Issue newIssue = model.ToIssue(); // here value will be splitted and add steps to table
   _issueRepository.AddIssue(Issue);
}

I would like to give an user a simple control to enter issue recreation steps.So I end up with the contenteditable attribute set to true for div element.

I have binded ReCreationSteps to Div element,but its not working.I can't get the value/html of DIV in ReCreationSteps property once the form is submitted.

Anyone help me on this or suggest me some other solution.

Hukam
  • 1,016
  • 18
  • 40
  • HukmChand - you don't show in your example code where you have defined your form. can you include that please and then hopefully it should be a little easier to figure the problem – jim tollan Jul 26 '12 at 11:36
  • ok, thanks see the form now. bit puzzled!!. you have no `` types inside the div, are these created dynmically somewhere else??. can you give a little fuller detail as to how you populate any `` elements inside you div. as it stands, there's a huge gap in my understanding of your process – jim tollan Jul 26 '12 at 11:44
  • First off, you have not bound the div to the model, creating a div and putting an id on it only works client-side. For anything to be bound, the value needs to be in the submit (post or get) when the form is submitted back to the server. – Steen Tøttrup Jul 26 '12 at 11:55
  • @jimtollan No i am not loading div dynmically.Just coded plain html in View itself and binded to ReCreationSteps property.I don't have any other details on this.As i am in developing stage trying to get this done. – Hukam Jul 26 '12 at 12:22
  • @SteenT I am just trying to get raw html to model property and split values into single steps and going to store in database. – Hukam Jul 26 '12 at 12:26
  • hukmchand - can i suggest that you whack absolutely everything that you have into the question. as i said, i'm clueless as to how you expect to derive any inputs from the div. binding to a div just doesn't happen outside of javascript, so a traditional form post won't see the div as an `` type (if you get tired of me saying that, then just skip :-)) – jim tollan Jul 26 '12 at 12:31
  • Are you saying that the "ReCreationSteps" property contains 'raw' HTML? You mention "splitting" the values from it. What does the data look like? Can you update your example? – anAgent Jul 26 '12 at 12:37
  • If you want to do this kind of dynamic form/html, use JSON, don't "push" the html to the server, represent your "form" with JSON and push the JSON to the server. – Steen Tøttrup Jul 26 '12 at 12:39
  • @jimtollan Thanks a lot for your help and info.I will try to use some other way. – Hukam Jul 26 '12 at 12:39
  • hukmchand - as anAgent says, I think you owe it to the interested parties here to shed a bucketful more light on this question as something doesn't gel. for starters, your IssueViewModel pays only fleeting resemblance to the properties inside your view, plus there's no logic to show what you're doing to populate the div that should contain our old friends the `` badboys. more, more more please. as they say `siso`. JSON or a partialview may be your best bet here – jim tollan Jul 26 '12 at 12:41
  • hukmchand - sorry for my continual questions on your question. but HOW are the steps being added, i.e. how are you adding new `
  • ` elements plus associated text??. this isn't clear at all from the included code. pop that bit down and I'm certain the mystery will be solved in a jiffy...
  • – jim tollan Jul 26 '12 at 13:05
  • @jimtollan Take a look at this [demo]http://html5demos.com/contenteditable/. just place your cursor at end of 3th line and tap enter key,fourth step will automatically added. – Hukam Jul 26 '12 at 13:22
  • ok, gotcha, so it's Html5 only that you're after... no worries – tho from the example you supplied (html5demos), there's a large section of javascript events that need to be added to your page code as well. Follow exactly what's going on it that demo and you should be fine. I never realised that you actually had a resource that you were able to refer to. – jim tollan Jul 26 '12 at 13:38
  • final question - from what you say in comments below, i presume that javascript is not an option?? if not, then I don't see how this is going to work alas. if js is allowable, then you're off to the races – jim tollan Jul 26 '12 at 14:23
  • @jimtollan js is allowable not ajax call.I am working on to keep some INPUT element as hidden and bind it to ReCreationSteps,before submitting the form just get raw html from div and update in hidden input's value.I hope it will work.I will update my answer once its completed. – Hukam Jul 26 '12 at 14:33