在前端与仅code。使用Orchard.Forms [英] Using Orchard.Forms on the front-end with code only
问题描述
我使用code创建使用Orchard.Forms一种形式。这是code我有:
I am using code to create a form using Orchard.Forms. This is the code I have:
public void Describe(DescribeContext context) {
Func<IShapeFactory, object> form =
shape => {
var f = Shape.Form(
Id: "MyLayoutBasicInformation",
_BasicInformation: Shape.Fieldset(
Title: T("Basic Information"),
_FirstName: Shape.TextBox(
Id: "FirstName", Name: "First Name",
Title: T("First Name"),
Description: T("The name for this field")
)
)
);
return f;
};
context.Form("MyLayoutBasicInformation", form);
}
大多数这种类型的code的用于呈现在管理UI字段。不过,我想使这个在前端和都没有成功。
Most of this type of code is used to render fields in the Admin UI. However, I am trying to render this in the front-end and have not been successful.
我试着用 [形状]
想不出如何把它变成这样。我也尝试创建一个 .cshtml
文件,但我不知道是什么code要么把它付诸表决。
I tried using [Shape]
but couldn't figure how to pull this into it. I also tried creating a .cshtml
file, but I don't know what code to put into it either.
如何使这种形式在前端的例子?我知道我可以使用自定义窗体创建一个内容类型来呈现上使用管理前端形式,但我想用code做到这一点。
Any examples of how to render this form in the front-end? I know I can use Custom Forms to create a Content Type to render a form on the front-end using the Admin, but I am trying to do this with code.
感谢您提前。
推荐答案
您可以注入 IFormManager
在你的类,并使用它的构建
的方法来建立一个新的形式。
You can inject IFormManager
in your class and use it's Build
method to build a new form.
private readonly IFormManager _formManager;
public YourClass(IFormManager formManager)
{
_formManager = formManager;
}
,然后调用构建
的方法是这样的:
var shape = _formManager.Build("MyLayoutBasicInformation");
这篇关于在前端与仅code。使用Orchard.Forms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!