1

enter image description hereHere is my controller:

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

        [HttpGet]
        public ActionResult formGeneric()
        {  
            var model = new FormViewModel();
            return View(model);
        }

        [HttpPost]
        public ActionResult formGeneric(FormViewModel formModel)
        {
            return View();
        }

Here is my setup in Sitecore:

controller Rendering:

controller: Website.Controllers.FormsController, Website

Action: formGeneric

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


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




    </div>

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

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

enter image description here

  • Where is your view? – Jarmo Jarvi Jul 28 '17 at 4:23
  • I updated the question and added the view – Paul T. Rykiel Jul 28 '17 at 4:29
  • where do you have the error? is it javascript ? what version of Stecore do you have – Vlad Iobagiu Jul 28 '17 at 4:36
  • I am on version 8.2 Sitecore, I am trying to place a controller rendering in a placeholder. I can copy the exact error – Paul T. Rykiel Jul 28 '17 at 4:45
  • can you remove the javascript from the view and try again? If it fix the problem can you add a condition to NOT add javascript in experience editor – Vlad Iobagiu Jul 28 '17 at 5:40

Browse other questions tagged or ask your own question.