简体   繁体   English

获取html文件内容并将其发送到asp.net mvc中的页面

[英]get the html file content and send it to page in asp.net mvc

I want get a content of html file using C# and the pass those into cshtml view page.我想使用 C# 获取 html 文件的内容并将它们传递到 cshtml 视图页面。 is this possible to do ?这有可能吗?

my main requirement is load a html file into TinyMCE editor content , which is located at another destination.我的主要要求是将 html 文件加载到位于另一个目的地的TinyMCE 编辑器内容中

but once I explore about this I saw given answers like below但是一旦我对此进行了探索,我就看到了如下给出的答案

You cannot give a path to the setContent function directly.您不能直接提供 setContent 函数的路径。 What you need to do is to get the html file contents backendside and send it to your page where you insert it into your editor using the setContent method.您需要做的是获取 html 文件内容后端并将其发送到您的页面,然后使用 setContent 方法将其插入到编辑器中。

but I dont know how to get the html file content and send it to page in asp.net mvc但我不知道如何获取 html 文件内容并将其发送到 asp.net mvc 中的页面

However I tried like below to insert html file using jquery但是我尝试像下面一样使用 jquery 插入 html 文件

    setup: function(ed) {
    ed.on("init", function(ed) {            
        $.get("myhtml.html", function (content) { 

            tinyMCE.activeEditor.setContent(content);

        });

    })}

but this once also not working for me.但这一次也不适合我。 any suggestion would be highly appreciate任何建议将不胜感激

This is very simple.这很简单。 Instead of using it from the jQuery i'll suggest to create the MVC controller action with string return type and then use File.ReadAllText method of System.IO assembly to get the content of the html file.我会建议使用字符串返回类型创建 MVC 控制器操作,而不是从 jQuery 使用它,然后使用 System.IO 程序集的 File.ReadAllText 方法来获取 html 文件的内容。

public class HomeController : Controller {
    public IHtmlString TyneMice()
    {
       return new MvcHtmlString(System.IO.File.ReadAllText("filename"));
    }
}

you can call this controller and action from jQuery.你可以从 jQuery 调用这个控制器和动作。

I hope this answer helps you.我希望这个答案对你有帮助。 If you need more detail on how to read the content from html file you can find here如果您需要有关如何从 html 文件中读取内容的更多详细信息,可以在此处找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将HTML内容发送到ASP.NET MVC JSON函数? - How to send HTML content to ASP.NET MVC JSON function? 如何在asp.net mvc 5中获取文件的内容类型 - How to get the File's Content Type in asp.net mvc 5 ASP.NET 5 MVC 6:如何配置启动以在不在任何mvc路由上时发送html文件 - ASP.NET 5 MVC 6: How to configure startup to send a html file when not on any mvc route 如何在 ASP.NET MVC 中使用 GET 请求发送 Content-Type 标头? - How can I send Content-Type header with a GET request in ASP.NET MVC? 如何使用ASP.NET MVC每天从另一个网页获取“content = source code”? - How to Use ASP.NET MVC to get “content=source code” from another web page once a day? 在现有的 ASP.NET MVC 页面中嵌入另一个 html 页面 - Embed another html page in an existing ASP.NET MVC page 在Asp.Net MVC Razor中将HTML视图作为电子邮件附件发送 - Send HTML view as an Email Attachment in Asp.Net MVC Razor 使用Asp.Net Mvc以编程方式在内容页面中定义节名称 - With Asp.Net Mvc programmatically define section name in content page 将HTML内容导出到ASP.NET MVC中的Excel - Export HTML content to Excel in ASP.NET MVC 发送列表以查看,填充并在asp.net mvc中获取它 - send a list to view,fill and get it in asp.net mvc
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM