Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7561073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:04:32+00:00 2026-05-30T13:04:32+00:00

I’m having trouble binding the selected value of a drop down list to the

  • 0

I’m having trouble binding the selected value of a drop down list to the correct property in my view model. I can’t see what I am doing wrong here. I’ve put the code that should help show what I’m doing below. I’ve omitted some things such as the population of the ‘AllFolders’ property of the view model, as it’s just a simple List with an object called ImageGalleryFolder.

Every time the form posts back, the ParentFolderId property is null without fail. This is driving me crazy and I’ve wasted a lot of time trying to work it out.

Can anyone see something I’m doing wrong?

This is the view model

public class ImageGalleryFolderViewModel
{
    [Required]
    public string Title { get; set; }

    public int Id { get; set; }
    public string CoverImageFileName { get; set; }
    public HttpPostedFileBase UploadedFile { get; set; }
    public string ParentFolderId { get; set; }
    public IList<ImageGalleryFolder> AllFolders { get; set; } 
}

Here is the view code

@using Payntbrush.Presentation.Demo.MVC3.Areas.Admin
@model Payntbrush.Presentation.Demo.MVC3.Areas.Admin.Models.ImageGalleryFolderViewModel

@{
    ViewBag.Title = "Create A New Gallery Folder";
}

<h2>@ViewBag.Title</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm((string)ViewBag.Action + "Folder", "Portfolio", FormMethod.Post, new { Id = "CreateFolder", enctype = "multipart/form-data" }))
{
    @Html.ValidationSummary(true)

        if(((string)ViewBag.Action).ToLower() == FormConstants.Edit.ToLower())
        {
            @Html.HiddenFor(m => m.Id)
            @Html.HiddenFor(m => m.CoverImageFileName)
            @Html.HiddenFor(m => m.ParentFolderId)
        }

        <div class="editor-label">
            @Html.LabelFor(model => model.Title)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Title)
            @Html.ValidationMessageFor(model => model.Title)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.UploadedFile)
        </div>
        <div class="editor-field">
            <input type="file" name="UploadedFile"/>
            @Html.ValidationMessageFor(model => model.UploadedFile)
        </div>


    {
        // Count > 1 is important here. If there is only 1 folder, then we still don't show the drop down
        // as a child folder can't have itself as it's own parent.
    }
    if(@Model.AllFolders.Count > 1)
         {
             <div class="editor-label">
                 Choose a parent folder (optional)
             </div>
             <div class="editor-field">
                    @Html.DropDownListFor(m => m.ParentFolderId, new SelectList(Model.AllFolders, "Id", "Title"))
             </div>


         }


    <p>
            <input type="submit" value="Save" />
        </p>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

I’ve ommitted my view, but this is what my form looks like when rendered in the browser. The form looks good from what I can see?

   <form Id="CreateFolder" action="/SlapDaBass/Portfolio/EditFolder/1" enctype="multipart/form-data" method="post">
<input data-val="true" data-val-number="The field Id must be a number." data-val-required="The Id field is required." id="Id" name="Id" type="hidden" value="1" />
<input id="CoverImageFileName" name="CoverImageFileName" type="hidden" value="" />
<input id="ParentFolderId" name="ParentFolderId" type="hidden" value="" />        


<div class="editor-label">

             <label for="Title">Title</label>

            </div>

            <div class="editor-field">

                <input class="text-box single-line" data-val="true" data-val-required="The Title field is required." id="Title" name="Title" type="text" value="Test" />

                <span class="field-validation-valid" data-valmsg-for="Title" data-valmsg-replace="true"></span>

            </div>

            <div class="editor-label">

                <label for="UploadedFile">UploadedFile</label>

            </div>

            <div class="editor-field">

                <input type="file" name="UploadedFile"/>

                <span class="field-validation-valid" data-valmsg-for="UploadedFile" data-valmsg-replace="true"></span>

            </div>

                 <div class="editor-label">

                     Choose a parent folder (optional)

                 </div>

                 <div class="editor-field">

                        <select id="ParentFolderId" name="ParentFolderId">
                           <option value="1">Test</option>
                           <option value="2">Test 2</option>

                         </select>

                 </div>

        <p>

                <input type="submit" value="Save" />

            </p>

    </form>

And this is the controller action:

[HttpPost]
        public ActionResult EditFolder(int id, ImageGalleryFolderViewModel model)
        {
            if (ModelState.IsValid)
            {
                Services.PortfolioService.UpdateFolder(model.MapToDomainModel(), model.UploadedFile);
                return Home;
            }
            return View();
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:04:34+00:00Added an answer on May 30, 2026 at 1:04 pm

    change the data type of the ParentFolderId

    public class ImageGalleryFolderViewModel
    {
        [Required]
        public string Title { get; set; }
    
        public int Id { get; set; }
        public string CoverImageFileName { get; set; }
        public HttpPostedFileBase UploadedFile { get; set; }
        public int ParentFolderId { get; set; }
        public IList<ImageGalleryFolder> AllFolders { get; set; } 
    }
    

    also use the Html helper for the dropdownlist

    <%: 
         Html.DropDownListFor(
               model => model.ParentFolderId , 
               new SelectList(
                      new List<Object>{ 
                           new { value = 1 , text = "Test"  },
                           new { value = 2 , text = "Test2" },
                           new { value = 3 , text = "Test3"}
                        },
                      "value",
                      "text"
               )
            )
    %>
    

    i hope you are strongly typing your view like

        public ActionResult EditFolder()
        {
    
            return View(new ImageGalleryFolderViewModel());
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Does anyone know how can I replace this 2 symbol below from the string
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.