[RESOLVED]ActionResult File not reading the newline

Hi,

I am listing the txt files from a folder aa a link and opens it in a modal dialog  when clicks on that.

I am listing the files as follows

 <div style="margin-top:5%;">
                @{  if ((Model!=null) && (Model.Count() > 0))
                    {
                       
                                          <ul>
                                             @foreach (var item in Model){
                                                 <li style="padding-top:1%;">
                                                     @Html.ActionLink(item.FileName, "OpenLogFile", "Admin", new { filename = item.FileName }, new { @class = "logfiles" })      

                                                 </li>
                                                       } 
                                                    </ul>
                                            @*@Html.DisplayFor(modelItem => item.FileName)*@
                                       

                    }
                    else{
                         <div>  <p class="vpgnorecords">No Log Files found in the directory !!!</p></div>
                    }
                    }
                    </div>

And the controller action is as follows

 public ActionResult OpenLogFile(string filename)
        {
             FileInfo info = new FileInfo(GetLogFilePath()+"/"+filename);
             return File(info.OpenRead(), "text/plain");
        }

And open this file in a dialog as follows

 $(".logfiles").click(function () {
            var url = $(this).attr('href');
            $("#dialog-edit").dialog({
                title: 'Log File Content',
                autoOpen: false,
                resizable: false,
                height: 800,
                width: 1000,

                show: { effect: 'drop', direction: "up" },
                modal: true,
                draggable: true,
                top: '100px',
                left: '50%',
                open: function (event, ui) {
                    $(this).load(url);

                },
                close: function (event, ui) {
                    $(this).dialog('close')
                }
            });

            $("#dialog-edit").dialog('open');
            return false;
        });

The opening div is as follows

<div>  <p class="vpgnorecords">No Log Files found in the directory !!!</p></div>

It opens the corrsponding txt files, but the file content is displaying as a single line without reading the newline character.

Its not reading the enter..its showing the whole content as a single line

How to Show the content as it is in the txt file

Pls help me

Thanks

Vidya

You can do one thing,

Store the data retreived from the Action and then on success, load the content as html like:

$("#DIALOG_ID").html(CONTENT);

$("#DIALOG_ID").dialog();

This would work out.

Load your file into

<pre>

your file here

</pre>

rather than

<div>

your file here

</div>

Leave a Reply