Very basic POST request problems

Topics: Writing modules
Apr 9, 2011 at 9:47 AM
Edited Apr 9, 2011 at 10:29 AM

Hi all,

What I'm trying to do: create simple form on the front-end

I'm using drivers and Display method to return my form - this part works without any problems at all.

My POST request sends data to my custom controller, action is executed and returns partial view - this is also all fine.

Problem: How can I access model from my controller, I tried puting my ____Part into parameters of Action, getting Model data using code from "contact" module:

var model = new AppFormRecord();
var form = Services.ContentManager.Get(id);
var contactForm = form.Parts.FirstOrDefault(p => p is AppFormPart);

Changing first line to : var model = Services.ContentManager.Create<AppFormPart>("AppForm");

I have a checkbox called "IsForYoungPeople", even when I try to access it though Request Form/Params dictionaries like that:


result is "true,false"...

"form.Record" contains "Data" property but it always contains "<Data />".

"contactForm" does not contains proper values either.


1) How can I access Model from the controller's action.

2) Is it not possible to handle "Display" POST request from Driver? I would expect that that should be possible since this is the place for handling POST request for Editor templates. If there is a way to handle POST request from withing the driver, I would appriciate example.

3) I didn't manage to get to this part yet but will "TryUpdateModel" save informaiton to database (whether it's save or update) ? How can I perform simple Select, Insert, update, Delete operations ?


(I tried using "shapeHelper.Parts_AppForm", passing individual properties to the model and using "Html.CheckBox("<property name>")" instead of CheckBoxFor. I'm using CheckBoxFor since I think it's nicer.)



        protected override DriverResult Display(AppFormPart part, string displayType, dynamic shapeHelper)
            return ContentShape("Parts_AppForm", () => shapeHelper.Partial(
                Model: part,                
                TemplateName: "Parts/AppForm"


My controller's action:


        public ActionResult ContinueToStep(int id)
            var model = new AppFormRecord();
            var form = Services.ContentManager.Get(id);

            var record = form.Record;

            var contactForm = form.Parts.FirstOrDefault(p => p is AppFormPart);

            //TODO:...access model data somehow

            return PartialView(@"Parts\AppFormStep2");


My cshtml filee "AppForm.cshtml":


@model Sported.ApplicationForm.Models.AppFormPart

<div id="myDiv">

    @using (Html.BeginForm("ContinueToStep", "AppForm",
        new { area = "MyTest.ApplicationForm" }, FormMethod.Post, 
        new { id="myForm"}))
        @Html.Hidden("Id", (int)Model.Id) 

        @Html.LabelFor(model => model.IsForYoungPeople)           
        @Html.CheckBoxFor(model => model.IsForYoungPeople)

        @Html.LabelFor(model => model.IsSportActivity)
        @Html.CheckBoxFor(model => model.IsSportActivity)

        @Html.LabelFor(model => model.IsSportForDevelopment)
        @Html.CheckBoxFor(model => model.IsSportForDevelopment)

        @Html.LabelFor(model => model.IsDisadvantagedCommunity)
        @Html.CheckBoxFor(model => model.IsDisadvantagedCommunity)

        @Html.LabelFor(model => model.FitsIntoCategories)
        @Html.CheckBoxFor(model => model.FitsIntoCategories)
        <input type="submit" value="Continue to Step 2" />



Thank you in advance for all your help.

Apr 10, 2011 at 2:32 PM


"TryUpdateModel" is assigning all form values to empty model passed as reference