0

Here is my View

@model Website.ViewModels.FormViewModel



<div class="container">

    <div class="col-sm-6">

        @Html.Raw(Model.content)


    </div>



    <div class="col-sm-6">
        <h2>@Model.formTitle</h2>

        <p class="large-subhead">@Model.formSubTitle</p>

        <p>@Model.formText</p>
        @using (Html.BeginRouteForm(Sitecore.Mvc.Configuration.MvcSettings.SitecoreRouteName, FormMethod.Post))
        {
            <div class="content-form">
                <div class="form-group form-group-lg">
                    @Html.TextBoxFor(x => x.fullName, new { @class = "form-control", @placeholder = "Full Name" })
                </div>
                <div class="form-group form-group-lg">
                    @Html.TextBoxFor(x => x.emailAddress, new { @class = "form-control", @placeholder = "Email Address" })
                </div>
                <div class="form-group form-group-lg">
                    @Html.TextBoxFor(x => x.streetAddress, new { @class = "form-control", @placeholder = "Street Address" })
                </div>

                <div class="form-group form-group-lg">
                    @Html.TextBoxFor(x => x.city, new { @class = "form-control", @placeholder = "City" })
                </div>



                <div class="input-group input-group-lg">
                    @Html.TextBoxFor(x => x.state, new { @id = "stateVal", @class = "form-control" })
                    <div class="input-group-btn">
                        @if (Model.states != null)
                {
                            @Html.DropDownList("StateList", Model.states, "State", new { @id = "stateDrop", @class = "btn btn-default dropdown-toggle" })
                        }
                    </div><!-- /btn-group -->
                </div>

                <div class="form-group form-group-lg">
                    @Html.TextBoxFor(x => x.zipCode, new { @class = "form-control", @placeholder = "Zip/Postal Code" })
                </div>

                @{
                    var countries = new List<SelectListItem>()
                {
                    new SelectListItem() { Text = "USA", Value = "USA" },
                    new SelectListItem() { Text = "CAN", Value = "CAN" },
                };
                }

                <div class="input-group input-group-lg">
                    @Html.TextBoxFor(x => x.country, new { @id = "countryVal", @class = "form-control" })
                    <div class="input-group-btn">
                        @Html.DropDownList("CountryList", countries, "Country", new { @id = "countryDrop", @class = "btn btn-default dropdown-toggle" })
                    </div>
                </div><!-- /input-group -->
                <!-- Hidden Fields from Model -->
                @Html.HiddenFor(x => x.pageId)
                @Html.HiddenFor(x => x.emailSubject)
                @Html.HiddenFor(x => x.replyMessage)
                @Html.HiddenFor(x => x.recipientEmail)
                @Html.HiddenFor(x => x.fromEmail);


                <input type="submit" class="inline-btn" name="@Model.buttonText"> 
            </div>
                    }




    </div>

</div>
<script>
    $(document).ready(function () {
        $('#stateDrop').change(function () {
            $('#stateVal').val($(this).val());
        });

        $('#countryDrop').change(function () {
        $('#countryVal').val($(this).val());
        });
    });
</script>

and here is my action in the Controller:

namespace Website.Controllers
{
    public class GenericFormsController : Controller
    {
        // GET: GenericForms
        public ActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public ActionResult GenericForm()
        {
            var dataSourceId = RenderingContext.CurrentOrNull.Rendering.DataSource;
            var dataSourceItem = Sitecore.Context.Database.GetItem(dataSourceId);

            var model = new FormViewModel();
            model.pageId = PageContext.Current.Item.ID.ToString();
            model.formTitle = dataSourceItem.Fields["Heading"].Value;
            model.formSubTitle = dataSourceItem.Fields["Sub Heading"].Value;
            model.formText = dataSourceItem.Fields["Form Text"].Value;
            model.content = dataSourceItem.Fields["Left Column Content"].Value;
            model.buttonText = dataSourceItem.Fields["Button Text"].Value;
            model.emailSubject = dataSourceItem.Fields["Email Subject"].Value;
            model.replyMessage = dataSourceItem.Fields["Reply Message"].Value;
            model.recipientEmail = dataSourceItem.Fields["Recipient Email"].Value;
            model.fromEmail = dataSourceItem.Fields["From Email"].Value;
            model.states = model.stateList();

            return View(model);
        }

        [HttpPost]
        public ActionResult GenericForm(FormViewModel model)
        {
            return View();
        }
    }
}

Note: I haven't added all of the code to process, but my breakpoint isn't even being hit, and it is loading the home page.

Browse other questions tagged or ask your own question.