在MVC中打开.htm文件需要帮助

时间:2015-06-29 07:19:19

标签: javascript jquery asp.net-mvc asp.net-mvc-4

我正在使用MVC4和Jquery。

我在通过MVC中的操作方法打开.htm文件时遇到了问题。

这是我的代码:

<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:

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

我在尝试打开时遇到问题。我得到的错误就像 '$'未定义。

请告诉我如何通过操作方法

打开.htm文件

2 个答案:

答案 0 :(得分:1)

请勿尝试将其作为FilePathResult,返回,并且不需要在此处复杂化。首先,将您的HTM文件放在项目的文件夹中,如Files

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

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

然后你可以通过以下方式链接到它:

<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。

答案 1 :(得分:0)

为什么要为此创建控制器条目?这是一个普通的.htm文件,您可以直接浏览.htm文件:

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

或者您可以选择将文件转换为.cshtml文件,在这种情况下您可以使用控制器return View(),确保为.cshtml文件指定正确的名称并将其放在正确的文件夹中

相关问题