[英]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.