[英]How do I set the initial content of a TinyMCE editor in ASP.NET MVC4 (Razor)?
I have followed this tutorial for grabbing TinyMCE via nuget and using it with Razor in MVC4. 我已经按照本教程通过nuget抓取TinyMCE并将其与MVC4中的Razor一起使用了。
All works well, but when my form loads, I need to place some default text in the TinyMCE control. 一切正常,但是在加载表单时,我需要在TinyMCE控件中放置一些默认文本。
How do I do that? 我怎么做?
The problem for me is that I am using Razor (which I normally don't do) and everything is abstracted (eg @Html.EditorFor(m => m.Message)
). 对我来说,问题是我正在使用Razor(通常不这样做),并且所有内容都是抽象的(例如@Html.EditorFor(m => m.Message)
)。 I can't see any "hooks" into TinyMCE that would let me set the content before the page renders. 我看不到TinyMCE的任何“钩子”,这会让我在页面呈现之前设置内容。
Got it sorted--You have to set the value in the controller. 得到排序-您必须在控制器中设置值。 So if you have this in your view: 因此,如果您对此有意见:
@Html.LabelFor(m => m.Message)
@Html.EditorFor(m => m.Message)
Then you need this in your controller: 然后,您需要在控制器中使用它:
public ActionResult Index()
{
var someValue = "foo"; //Get your data here
var model = new CorporateAccountModel {Message = someValue};
return View(model);
}
That's it. 而已。 No additional coding is required in the view, which makes me a little uncomfortable but works. 视图中不需要其他编码,这使我有些不舒服但可以使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.