Click here to Skip to main content
15,888,133 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear sir/madam
i am using tinymce editor in my view and i am saving the image with other content written in editor.
the problem is when i show the content in view then all the content are displayed leaving the image.

Here is my code of controller
public JsonResult upload()
       {
           var file = Request.Files["file"];
           //string extension = Path.GetExtension(file.FileName);
           //string fileid = Guid.NewGuid().ToString();
           //fileid = Path.ChangeExtension(fileid, extension);
           var filename1 = Path.GetFileName(file.FileName);
           string locationn = Server.MapPath(@"~/Uploads/img/" + filename1);
           file.SaveAs(locationn);
           //HttpPostedFileBase f1 = Request.Files["f1"];
           //var filename1 = Path.GetFileName(f1.FileName);
           //var p1 = Server.MapPath("~/contnt/images/" + filename1);
           //f1.SaveAs(p1);
           //var pic1 = Url.Content(Path.Combine("~/contnt/images/" + filename1));
           return Json(new {location= Url.Content(Path.Combine("~/Uploads/img/" + filename1))}, JsonRequestBehavior.AllowGet);
      }


this is View code
<div class="content table-responsive table-full-width">
    <link href="~/Scripts/Uploadify/uploadify.css" rel="stylesheet" />
    <script src="~/Scripts/UPLODIFY/jquery.uploadify.min.js" type="text/javascript"></script>
    <script src="~/Scripts/tinymce/tinymce.min.js"></script>
    <script>
tinymce.init({
selector: 'textarea',
height: 500,
theme: 'modern',
skin: "lightgray",
plugins: [
'advlist autolink lists link image charmap print preview hr anchor pagebreak',
'searchreplace wordcount visualblocks visualchars code fullscreen',
'insertdatetime media nonbreaking save table contextmenu directionality',
'emoticons template paste textcolor colorpicker textpattern imagetools'
],
toolbar1: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | image',
toolbar2: 'print preview media | forecolor backcolor emoticons ',
    //image_advtab: true,
images_upload_url: '/Account/upload',
images_upload_credentials: true,
automatic_uploads: true
});
    </script>
    @*<script src="~/Scripts/jquery-1.10.2.js"> </script>
    <script type="text/javascript">
        $(function(){
            $("[name=filee]").on("change", function ()
            {
                var file=$(this).val()
                alert(file)
                $.ajax({
                    type: 'get',
                    url: '/Account/upload'
                    });
            });
        });
    </script>*@
               @using (Html.BeginForm("AddNews", "Account", FormMethod.Post,new { enctype = "multipart/form-data"}))
               {

                    <table class="table table-striped">
                      <tbody>
                            <tr><td>@Html.DropDownList("newstype",new SelectList(Enum.GetValues(typeof(newsportal.Models.newstype))),new {id="ntype"})</td></tr>
                            <tr><td>Date</td><td>@Html.TextBoxFor(Model => Model.datee, new { @type = "date",paceholder="select date"})</td></tr>
                            <tr><td>Country</td><td>@Html.TextBoxFor(Model => Model.country)</td></tr>
                            <tr><td>State</td><td>@Html.TextBoxFor(Model => Model.statee)</td></tr>
                            <tr><td>City</td><td>@Html.TextBoxFor(Model => Model.city)</td></tr>
          <tr><td>Category</td><td>@Html.DropDownListFor(Model=>Model.cat, new SelectList(Enum.GetValues(typeof(newsportal.Models.category))),"Select Category")</td></tr>
                            <tr><td>SubCategory</td><td>@Html.TextBoxFor(Model => Model.subcat)</td></tr>
                           <tr><td>URL Title(only for hindi news)</td><td>@Html.TextBoxFor(Model=>Model.urltitle)</td></tr>
                          <tr><td>Enter The News Youtube Url</td><td>@Html.TextBoxFor(Model=>Model.videourl)</td></tr>
                            <tr><td>Title</td><td>@Html.TextAreaFor(Model => Model.title)</td></tr>  
                           <tr><td>Content</td><td>@Html.TextAreaFor(Model => Model.content)</td></tr>
                            <tr><td>pic1</td><td><input name="f1" type="file" /></tr>
                            <tr><td>Writer</td><td>@Html.TextBoxFor(Model => Model.writ)</td></tr>
                            <tr><td><input type="submit" /></td></tr>
                      </tbody>
                     </table>
               }
</div>


this is the view where i display the content

<pre>div class="content_bottom_left">
        <div class="single_page_area">
            <h2 class="">@ne.title</h2>
            <div class="single_page_content">
                <div class="post_commentbox"> <a href=@Url.Action("Home","News")>class="fa fa-user">@ne.datee</span> <a href="#">^__i class="fa fa-tags">@ne.cat</a> </div>
                <img class="img-center" src=@ne.pic1 alt="" style="height:430px;">
                @Html.Raw(ne.content)
            </div>


What I have tried:

i didnot tried anything else laving this.
Posted
Comments
F-ES Sitecore 19-Mar-18 5:28am    
You're not passing the file to the ajax method neither are you processing the result to show the image on the page so I'm struggling to understand why you think this code would ever work?

There's not enough context here for anyone to really understand what you're doing, but I suggest you find a working example of a file upload using tinymce and compare the working solution with what you are doing to work out what is wrong.
[no name] 19-Mar-18 7:38am    
i am not using ajax. the script has been commented in view(i think u didn't see that).
images_upload_url: '/Account/upload',
as soon as i select the image the upload will be called
F-ES Sitecore 19-Mar-18 7:48am    
I don't see anywhere that your upload code is called. This is one of the problems with code dumps, just post the relevant bits of code.
[no name] 19-Mar-18 7:54am    
The upload code is called when i upload the file using upload image option in tinymce.
from here the upload code is being called
images_upload_url: '/Account/upload',
Richard Deeming 19-Mar-18 10:31am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900