Orchard Form passing input values are not up to date

Topics: Core, General, Writing modules
Apr 2, 2013 at 4:31 AM
I have implemented input form name "ConfigurationForm" to work just insert or update one record for configuration values inside database.

I have done created C# Razor html as ConfigurationForm.cshtml following below code.
@using System.Web.Mvc
@model Euronome.DB.Models.ConfigurationPart
<fieldset>
    <legend>Configuration Fields</legend>

@* @using (Html.BeginForm("Update", "ConfigurationForm", FormMethod.Post))
 {*@
       
    <div class="editor-label">@Html.LabelFor(model => model.con_att_fact)</div>
    <div class="editor-field">
        @Html.EditorFor(model => model.con_att_fact)
        @Html.ValidationMessageFor(model => model.con_att_fact)
    </div>
    <div class="hint">Enter the con att factor here</div>
 
    <div class="editor-label">@Html.LabelFor(model => model.con_cc_fact)</div>
    <div class="editor-field">
        @Html.EditorFor(model => model.con_cc_fact)
        @Html.ValidationMessageFor(model => model.con_cc_fact)
    </div>
    <div class="hint">Enter the con cc factor here</div>

    <div class="editor-label">@Html.LabelFor(model => model.con_from_fact)</div>
    <div class="editor-field">
        @Html.EditorFor(model => model.con_from_fact)
        @Html.ValidationMessageFor(model => model.con_from_fact)
    </div>
    <div class="hint">Enter the con from factor here</div>

    <div class="editor-label">@Html.LabelFor(model => model.con_size_calc)</div>
    <div class="editor-field">
        @Html.EditorFor(model => model.con_size_calc)
        @Html.ValidationMessageFor(model => model.con_size_calc)
    </div>
    <div class="hint">Enter the con size factor here</div>

    <div class="editor-label">@Html.LabelFor(model => model.con_text_fact)</div>
    <div class="editor-field">
        @Html.EditorFor(model => model.con_text_fact)
        @Html.ValidationMessageFor(model => model.con_text_fact)
    </div>
    <div class="hint">Enter the con text factor here</div>

    <div class="editor-label">@Html.LabelFor(model => model.con_to_fact)</div>
    <div class="editor-field">
        @Html.EditorFor(model => model.con_to_fact)
        @Html.ValidationMessageFor(model => model.con_to_fact)
    </div>
    <div class="hint">Enter the con to factor here</div>
@*     
    <input type="submit" value="Update" />
 }*@

 @using (Html.BeginFormAntiForgeryPost(Url.Action("Update", "ConfigurationForm", new
 {
     con_att_fact = Model.con_att_fact,
     con_cc_fact = Model.con_cc_fact,
     con_from_fact = Model.con_from_fact,
     con_size_calc = Model.con_size_calc,
     con_text_fact = Model.con_text_fact,
     con_to_fact = Model.con_to_fact,
     area = "Euronome.Forms"
 })))
 {
    <input type="submit" value="Update" />
 }

</fieldset>
On my driver I have modified a change to make Display method showing directly an edit form of configuration below.
//Display GET
        protected override DriverResult Display(ConfigurationPart part, string displayType, dynamic shapeHelper)
        {
            if (part.Record == null)
            {
                NHibernate.ISession _session = _SessionLocator.For(typeof(ConfigurationRecord));
                part.Record = _DBFunctions.Get_Configuration(_session);
            }
            ContentShapeResult csr =
                ContentShape("Parts_ConfigurationForm_Edit", () => shapeHelper.EditorTemplate(TemplateName: "Parts/ConfigurationForm",
                    Model: part, Prefix: Prefix));
            return csr;
        }
An issue is when I clicked on submit button on ConfigurationForm.cshtml the passing values to controller which I implemented below is not up to date as user put a new input to the form.
[HttpPost]
       public ActionResult Update(double con_att_fact, double con_cc_fact, double con_from_fact, bool con_size_calc, double con_text_fact, double con_to_fact)
       {
...
           return View();
       }
Apr 5, 2013 at 2:24 AM
Hi Orchard forum,

Just wanna describe in text the issue that kraisorna is describing here.

We have run into some trouble, and I'm sure, that Orchard have a easy way to fix it - but we can not find it.

Normaly when you want to edit input data in orchard, you go through first a display screen with data (list of data), then you push edit to enter the updating form.

We have a record that only contain configuration for the system, it have only one record, so what we would like orchard to do, is to call our edit form directly from the main menu

It is easy to call the edit form directly, by writing it like this in the display driver
        ContentShapeResult csr =
            ContentShape("Parts_ConfigurationForm_Edit", () => shapeHelper.EditorTemplate(TemplateName: "Parts/ConfigurationForm",
                Model: part, Prefix: Prefix));
        return csr;

But here comes the problems, when we need to save the editform back to the database. We have not the save button, and when we try to submit the editform, the fields are empty, so we just save an empty record - have anyone tried this, or are there any best practices or hack we can use, to get this form done


Thank you



/Peter
Team Manager - Euronome
Developer
Apr 6, 2013 at 5:12 PM
Perhaps the best way to do this is by attaching your custom part to the Site content type and implement it as site settings.
Apr 9, 2013 at 4:50 AM
sfmskywalker wrote:
Perhaps the best way to do this is by attaching your custom part to the Site content type and implement it as site settings.
I am creating a new content from Site content type, but there is no Site to select on "Create New Content" page. How can I enable Site content type to be able to create as a new content?
Developer
Apr 9, 2013 at 12:21 PM
In what scenario would you want to create a new Site content item?
Apr 9, 2013 at 3:58 PM
sfmskywalker wrote:
In what scenario would you want to create a new Site content item?
I am going to attach a custom configuration form part to the Site content type, and then create a new Site content item from it.
Developer
Apr 9, 2013 at 7:28 PM
Ok, I'm sure you know what you're doing, but I don't think you want to create a new Site content item. Instead I would use the existing Site content item accessible via IOrchardServices and WorkContext.