Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...