2015-06-29 27 views
-1

我正在使用MVC4和Jquery。在MVC中打开.htm文件需要帮助

我在通过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; 
} 

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

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

+0

正确格式化 – Ionic

回答

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文件的名称正确并将其放在正确的文件夹中。

+0

我想对.htm文件应用授权,以便用户无法直接从外部打开,而无需进行身份验证。我将其添加到操作方法中。 –

+0

然后,您需要将其创建为.cshtml并使用适当的MVC方式返回视图。 – JanR

+0

在MVC视图中呈现.htm文件的任何帮助。 –

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。

+0

我试过这个,但它不工作或authenticating.Even当我试图使用该网址打开htm文件的开放与出来要求认证 –