0

I am using Mvc 5 razor,and have used ckeditor to save data in database but when i am retrieving data on the view it is coming with all the html tags pls helpme how to display it in normal text form on the view

     <div class="panel panel-default">
                        <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree" id="Inclusions">
                            <div class="panel-heading">
                                <h4 class="panel-title">  INCLUSIONS </h4>
                            </div>
                        </a>
                        <div id="collapseThree" class="panel-collapse collapse">
                            <div class="panel-body">
                                @Html.Raw(Html.DisplayFor(Model => Model.Itinerarydetail.Inclusions));
                            </div>
                        </div>
                    </div>
1
  • You can use @Html.Raw for displaying raw html data, if that's what you are looking for. But I suggest you to edit your post and add your code, that you actually do to save and draw your field. Commented Dec 29, 2015 at 10:15

2 Answers 2

4

When you use the Html.DisplayFor helper method, razor will encode the content before rendering. You should use Html.Raw() helper method which will not encode your content and pass the value you want to render directly to that.

<div class="panel-body">
    @Html.Raw(Model.Itinerarydetail.Inclusions)
</div>
Sign up to request clarification or add additional context in comments.

2 Comments

Will this cause XSS vulnerability?
Here we are not showing the encoded version. So in that case, We should encode it in the action method before sending to view.
1

Here in my view when you get data from database use @Html.Raw

<div class="form-group">
        @Html.LabelFor(model => model.Description,htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-sm-8">
            <textarea type="text" class="ckeditor" name="Description">@item.Description</textarea>
            @Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
        </div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.