Summernote and presentation form in MVC C #

I am using summernote plugin for text field: http://summernote.org/#/getting-started#basic-api

This is the form in which I use summmernote:

<div class="modal-body" style="max-height: 600px"> @using (Html.BeginForm()) { @Html.ValidationSummary(true) <fieldset class="form-horizontal"> <div id="textForLabelLanguage"></div> <button type="submit" class="btn btn-primary">Save changes</button> @Html.ActionLink("Cancel", "Index", null, new { @class = "btn " }) </fieldset> } </div> <script type="text/javascript"> $(document).ready(function () { $('#textForLabelLanguage').summernote(); }); </script> 

Now, in my controller, this is the code I have:

 public ActionResult Create(UserInfo newInfo , [Bind(Prefix = "textForLabelLanguage")] string textForLabelLanguage) { //logic here } 

Now the problem is that the textForLabelLanguage parameter textForLabelLanguage always null.

This is because I have to pass $('#textForLabelLanguage').code(); in MVC when submitting a form, but I have no idea how to do this!

How to solve my problem?

+7
c # asp.net-mvc forms summernote
source share
3 answers

I found a solution to the problem. This is how I make the controller to get the right information:

 <div class="modal-body" style="max-height: 600px"> @using (Html.BeginForm()) { @Html.ValidationSummary(true) <fieldset class="form-horizontal"> <textarea name="textForLabelLanguage" id="textForLabelLanguage" /> <button type="submit" class="btn btn-primary">Save changes</button> @Html.ActionLink("Cancel", "Index", null, new { @class = "btn " }) </fieldset> } </div> <script type="text/javascript"> $(document).ready(function () { $('#textForLabelLanguage').summernote(); }); </script> 

Basically, if I use a text box with a name instead of input or something else, it works!

However, and be careful, although this solution works, I then get an error message in the controller:

The potentially dangerous Request.Form value was detected by the client

This is because I enable HTML. But this is a problem for another question!

+12
source share

Please use [AllowHTML]

There's a good article on MSDN Validating a Request in ASP.NET

"To disable request validation for a specific property, mark the property definition with the AllowHtml attribute:"

 [AllowHtml] public string Prop1 { get; set; } 
+3
source share

similar to what was published earlier, you can use the HTML helper @ HTML.TextAreaFor (m => m.text, new {@id = "textForModel"}) instead

0
source share

All Articles