0

Content file.txt:

Line 1. Hello world!!

Line 2. Ajax's fantastic.

At index.cshtml. What i want is:

<div id='ViewFile'>
Line 1.      Hello world!!
Line 2.      Ajax's fantastic.
</div>

In fact, I got:

<div id='ViewFile'>
Line 1.Hello world!!Line 2.Ajax's fantastic.
</div>

Please let me know how to load original file.txt into div-id='ViewFile'

2
  • use </br> for new line Commented Aug 28, 2016 at 17:02
  • what about "\t" (tab). I mean spacing Commented Aug 28, 2016 at 17:05

1 Answer 1

2

Instead of <div> use <pre>, this tag preserves the line breaks:

View:

@Ajax.ActionLink("Click To View File", "GetFile", new AjaxOptions { UpdateTargetId="ViewFile" })
<pre id='ViewFile'>
</pre>

Controller:

public FileResult GetFile()
{
    return File("~/file.txt", System.Net.Mime.MediaTypeNames.Text.Plain);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Please remember to mark as answered if it helped you

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.