需要在MVC打开.htm文件帮助 [英] Need help in opening .htm file in MVC

查看:67
本文介绍了需要在MVC打开.htm文件帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MVC4和jQuery。

I am using MVC4 and Jquery.

我有在通过行动方法MVC打开.htm文件的问题。

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

下面是我的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');"/>

我ActionMethod:

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;
}

我现在面临的问题,而试图open.I我得到错误,如
$是不确定的。

请让我知道我可以打开.htm文件通过行动方法

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

推荐答案

不要尝试,并返回它作为一个 FilePathResult,有没有必要在这里过于复杂的事情。首先,把你的HTM文件的文件夹内的项目,像文件

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.

现在,以下内容添加到您的web.config prevent未经授权访问您的文件:

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');"/>

当你在这,你可能要考虑一下消除这些内联样式和使用类名称和内联JavaScript了。

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.

这篇关于需要在MVC打开.htm文件帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆