Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
150 views
in Technique[技术] by (71.8m points)

javascript - Need help in opening .htm file in MVC

I am using MVC4 and Jquery.

I am having issue in opening the .htm file through action method in MVC.

Here is my Code:

<img src="~/Images/question_frame.png" style="margin-top:3px;height:18px;width:20px;" onclick="window.open('@Url.Action("Help", "Home", new { id = "NMCHelp"})', 'NMCHelp',toolbar=no, scrollbars=yes, resizable=yes, top=50, left=50,width=750, height=600');"/>

My ActionMethod:

[HttpGet]
[Authorize]
public ActionResult Help(){
    var result = new FilePathResult("~/help/nmc/enu/Default.htm", "text/html");![enter image description here][1]
    return result;
}

I am facing issue while trying to open.I am getting error like '$'is undefined.

Please let me know how can I open the .htm file through action method

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Don't try and return it as a FilePathResult, there's no need to overcomplicate things here. Firstly, put your HTM file inside a folder in your project, something like Files.

Now, add the following to your web.config to prevent unauthorised access to your file:

<location path="Files">
    <system.web>
        <authorization>
            <deny users="?" />
        </authorization>
    </system.web>
</location>

And then you can link to it by doing:

<img src="~/Images/question_frame.png" 
    style="margin-top:3px;height:18px;width:20px;" 
    onclick="window.open('/Files/Default.htm', 'NMCHelp',toolbar=no, scrollbars=yes, resizable=yes, top=50, left=50,width=750, height=600');"/>

While you're at it, you might want to think about removing those inline styles and use a class name and the inline JavaScript too.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...