How can I insert the Save Button using Orchard.Forms?

故事扮演 提交于 2019-12-08 01:06:20

问题


Follow-up to my initial question:

If I create a form in code thusly:

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);
}

And inject it into the front-end view thusly (as the answer provided):

var shape = _formManager.Build("MyLayoutBasicInformation");

My display just shows the field First Name. But there is no button to save it to the DB. Any thoughts on how to accomplish that?

UPDATE: I am working with my own custom module. I do have a custom theme applied to it. ShapeTracing is giving me alternates to place in the theme - which I don't know that I want to do.

I put the Build code in my controller thusly:

[Themed]
    public ActionResult BasicInformation()
    {
        var basicInformation = _formManager.Build("MyLayoutBasicInformation");
        return new ShapeResult(this, basicInformation);
    }

Initially, I hard-coded fields with the HTML helpers. So if my controller was MyController, I had a view like this: ~/Views/My/BasicInformation.cshtml. That file still exists in the module but is now overriden by the Build code.

I suspect I have to toy around with that.

UPDATE: I managed to to do this in the function to get a button showing, just have to figure out how to wire it up.

_NextButton: Shape.Button(
Id: "NextButton", Name: "Next",
Title: T("Next")
    )

But this just displays a button with no text.


回答1:


By default submit button will not generated for any form built this way. to add submit button to your form change your code as following :

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")
                        )
                    ),
                    _Submit:Shape.Submit(Value:"Save") 
                );
            return f;
        };
    context.Form("MyLayoutBasicInformation", form);
}


来源:https://stackoverflow.com/questions/17372182/how-can-i-insert-the-save-button-using-orchard-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!