Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Fernando Camillo 41 posts 82 karma points
    Sep 21, 2017 @ 20:43
    Fernando Camillo
    0

    Creating Forms with select field

    Hi. I'm new to Umbraco 7. I created a contact form using the Creating Forms documentation. It worked.

    Now I'm trying to create a subject field of type select with some options from the controller.

    My controller:

    public class ContactFormController : SurfaceController
    {
        public ActionResult Index()
        {
            var theOptions= new List<SelectListItem>
            {
                new SelectListItem() {Text = "Option 1", Value = "1"},
                new SelectListItem() {Text = "Option 2", Value = "2"},
                new SelectListItem() {Text = "Option 3", Value = "3"}
            };
            ViewBag.DdlSubject = theOptions;
        }
    
        [HttpPost]
        public ActionResult Submit(...)
        {
            etc... (it works)
        }
    }
    

    And my partial view:

    @model MyProject.Models.ContactFormModel
    
    @{
        List<SelectListItem> listSubjects = ViewBag.DdlSubject;
    }
    
    @using (Html.BeginUmbracoForm("Submit", "ContactForm"))
    {
        @Html.DropDownListFor(x => x.Subject, listSubjects, "-- select --")
        ... other fields and submit button ...
    }
    

    But the Index method of my controller is never hit. What am I missing?

    Thanks in advance.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies