Home » Asp.net

Masterpage Dropdown list

I have a dropdownlist on my master page which contains entries whose ID's basically drive the rest of the site.

When a user chooses an item in the dropdown list, the value of the dropdownlist is stored in a session and that value is used to pull the correct data.

My problem is that im getting the error "Child actions are not allowed to perform redirects". I have a base controller, which contains two methods that render the contents of my model for the masterpage.

    public class MasterPageController : Controller
        public ActionResult DropdownList(){
            MasterViewModel m = new MasterViewModel ... shortened.
            return View(m);

        public ActionResult DropdownList(FormCollection collection)
            //removed, basically just sets the session id, gets the model
            return RedirectToAction("Default", "Home", new { id = collection.Get("IDList").ToInt32() });

The dropdown list is rendered in my masterpage like so:

<%Html.RenderAction("DropdownList"); %>

This works fine, I can set the dropdown, it picks up the right values just fine.... Until I make a post that is not from the dropdownlist form.

So whats happening is I have a view in which im creating some data, saving it. During the creation process, my model did not pass validation, so I had to return back to the page and display the errors. When i return the View, it goes through the masterpage and hits the RenderAction method. Inside this its hitting the HttpPost action and trying to redirect while the view is currently rendering.

How do I get around this? Am I on the right track for having a persisted dropdownlist on a masterpage?


12 Answers Found


Answer 1

Do you have your DropDownList in it's own form  tag? 


Answer 2

Yes I do, it points to the DropdownList with HttpPost attribute in my base  controller.


Answer 3

I have created a simple test project to reproduce the issue. Using the default MVC 2 Application, I modified the Master page's RenderPartial method  for the Login control to this.

<div id="logindisplay">
       <% Html.RenderAction("ErrorTest", "Home"); %>

In the HomeController, I created two methods  that will do stuff when my dropdownlist  is used.

        public  ActionResult ErrorTest()
            List<SelectListItem> items = new List<SelectListItem>();

            for (int i = 0; i < 10; i++)
                items.Add(new SelectListItem
                    Text = i.ToString(),
                    Value = i.ToString()
            TestViewModel test = new TestViewModel();
            test.DropDownItems = items;
            return  View(test);

        public ActionResult ErrorTest(string test)
             return RedirectToAction("Index");

I then created a ViewModel to return to my view

    public class  TestViewModel
        public IEnumerable<SelectListItem> DropDownItems { get; set; }

I created the User control (ErrorTest.ascx)

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MvcApplication2.Models.TestViewModel>" %>
    <% using (Html.BeginForm("ErrorTest", "Home", FormMethod.Post, new { id = "ErrorList" }))
        { %>
        <span style="color: #333; font-size: 14px; font-weight: bold;">Select somthing: </span>
        <%= Html.DropDownList("Errors", Model.DropDownItems, " -- error  DropDown! --", new { style = "width:200px;", onchange = " $(\"#ErrorList\").submit()" })%>
    <%} %>

And now I can create a form  on any view, submit the form, and the error is reproduced.

I dont get why when there is a post, the public ActionResult ErrorTest(string test) method is getting picked up. I didnt post  to this?


Answer 4

The point is that you cannot do a redirect  to another page  form an action method  od a control that is in the master  page.....The flow of control can only be decided by the principal view! A redirect is actually a redirec involving also the browser, not simply a call of another method. MVC don't know how to translate this redirect! To do a redirect you need to specify a full page not only a piece of master page. Substitute the redirect with a simple method call of a non-action method that is used by the two actions  that need it.


Answer 6

francesco abbruzzese:

The point is that you cannot do a redirect  to another page  form an action method  od a control that is in the master  page.....The flow of control can only be decided by the principal view! A redirect is actually a redirec involving also the browser, not simply a call of another method. MVC don't know how to translate this redirect! To do a redirect you need to specify a full page not only a piece of master page. Substitute the redirect with a simple method call of a non-action method that is used by the two actions that need it.


If I do this, the RenderAction will not render  anything if it's not returning view  information.


i think that you are looking for a partial view

try this link


Do you have anymore indepth examples of this? From what ive been reading, partial views only display data  and do not accept post  data. I also need to pull  dynamic content and I cannot find any examples that demonstrate partial views beyond the display  of text/ViewData.


Answer 7

If I do this, the RenderAction will not render  anything if it's not returning View information.

The problem  is tah it returns NOTHING in any case it just say to the browser to go to another page  to display  something....The point that the vie you redirect  to is not able to render a full page.


Answer 8

It is likely that all of your other form  posts use the basic Html.BeginForm without any parameters. If that is the case, then they will execute the DropDownList action  in your base  controller because of the "POST." To correct  this, you would need to specify the action for every form (Html.BeginForm("MyAction")).

You might be able to use a custom selector to only match your DropDownList action when that specific form is executed while ignoring all other POSTS. Look into creating a custom selector from ActionNameSelectorAttribute.


Answer 9

After thinking about it for a bit, you really do need to go with rendering a partial view  instead of an action. You can provide the data  necessary for the dropdownlist  in the constructor of your base controller. The following is a quick example:


    public  abstract class  BaseController : Controller
        public BaseController()
            var items = new List<SelectListItem>
                                new SelectListItem {Text = "Test 1", Value = "1"},
                                new SelectListItem {Text = "Test 2", Value = "2"}
            ViewData["DemoDropDownListData"] = items;

        public ActionResult DropDownList(int id)
            return  RedirectToAction("Index", "Home");


<% Html.RenderPartial("DropDownList", ViewData["DemoDropDownListData"]); %>


<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<SelectListItem>>" %>
    <% using(Html.BeginForm("DropDownList", "Home", FormMethod.Post, new { id = "DropDownListTest"})) { %>
    <%: Html.DropDownList("id", Model, new { onchange = "$('#DropDownListTest').submit()"}) %>
    <% } %>



Answer 10

I tried this solution by adding my model  to ViewData and when I submit the form  I get a 404, cant find the Home/Dropdownlist URL.



Answer 11

I tested the previously mentioned solution and it worked as expected. Show the code for your controller, view, and model. I'll try to reproduce your issue and see what's happening.


Answer 12

Well I got it working, i was using the BaseController in the form, that was why it wasn't finding it.

Thanks for the help everyone!.



After upgrading from MOSS 2007 to SharePoint 2010, the following issue is now occurring in the new and edit forms when not displayed in the "dialog" window. 

List of options for a dropdown column in a SharePoint 2010 list when viewed by a link created that pointed to the new or edit form shows the list options in a off-center or skewed location and not direclty under the drop down box.  This could be inches below and inches to the right typically.  When the new or edit form is shown in a dialog window using the "new item" link at the end of the list or in the Ribbon, the dropdown list items are displayed directly below the box appropriately.

Additionally, this appear to happen ONLY with dropdowns with more than 20 options to choose.

Any ideas to what is causing this?

Does anyone know how to do this so when I select something the 1st dropdown and the 2nd one becomes visible and populates list from a Select statement. How do you code this in Sharepoint Developer on an aspx page?


I have two related external lists.  One is a lookup list, call it Education Level that relates to the other, call it Participant.

I know how (with caveats) to create an association between the two so that I can use the Picker to select an Education Level when editing the Participant.  This works for me as long as the Participant actually carries the text of the Education Level, not its numeric ID.  If I use the ID the picker works but the display of Education Level for the Participant is the ID.

The picker is good for some things, but I'd really like a good, old fashioned dropdown list of Education Levels.  There has to be a way - I can't believe how many hours of thrashing hasn't resolved this...  How can I do this?

Thank you!




I have 2 sharepoint lists one with columns users and country and other is a country list.

In infopath there are 2 dropdowns, 1 for user and 1 for country. User dropdown list is dependant on country dropdown. when i select a country, the users dropdown should consist of only users who belong to the selected country.

I have created data connections for both sharepoint lists. The infopath form is browser enabled and the filter data for retrieved data is not supported in browser enabled form. I am stuck now.

Can this be achieved? if yes, How? Plz help...


Ritesh Udupa


I have a Usercontrol wherein items are populated from lists. The dropdown fields needs to take account into language variations.i.e., i have lists for dropdownlist field data.if i want to enable translation to them how would i approach.

i have resource files for text data displayed on forms but for data which comes from moss list how would set it.


Hi All,

I have two drop downs in one row... when you  editing the row,  these dropdowns value gets populated...but I want to display values in 2nd drop base on selecttion of  1st drop down value...

When initially gridview populates, it displays all records in a label.control... as soon as u click on edit button.... for 1st and 2nd col... populate dropdown values...... so In EDIT mode..if you select drop value of 1st ddl then base on that value 2nd drop down should get populate.....

Please help ASAP....



Hello all, and thanks in advance for any help.

We've built a custom masterpage layout and so far it works great.  We have specified a layout based on tables that fix the width at 960pixels.  The tables are centered on the screen and have a particular background that is different from the page's background to make the content pop.  It works fine in most cases and still displays all MOSSs dynamic contents like the quicklaunch bar at left, etc.  The theme sort of looks like this : http://www.sharepointpackages.com/index.php?main_page=product_info&cPath=65&products_id=268&zenid=a045f5b7dba91fdab94d754569e0b611

The problem is that when a list has too many columns and is therefore wider than the 700 or so pixels that are left over for the placeholders inside the table, the list continues on, but does not affect the table itself.  In other words it appears as if the content was placed OVER the tables in the layout.  This is odd first of all, but it is actually bad in a way, because even if I use styles on the table cells that hold these placeholders, and have the overflow use scrolls, the table ACTUALLY does not see an overflow and the contents continue to run through without activating the scrollbars (they don't even show up). 

Can anyone help.  Please, Please, I've been looking at HTML for two days straight now trying to figure out what is happening to no avail.  If anyone wants to see the rendered HTML or anything like that, please let me know and I will provide it.

Thanks again.





   I want to add the new item to the list, the name of the list called "Mylist". I have the link in the another sharepoint site page.The requirment is when the user click on the link, the popup window will come and inside that "NewForm.aspx" of myList will display. normally if we display masterpage also get display i dont want to display the masterpage. Just i want to display "NewForm.aspx" in side the POPUP window. How to display like this?


I have 2 drop down lists.

I have a very simple dropdown list #1 that diplays a title and holds an id value which is a GUID.

I know it is getting this value and sending this value as I tested sending it to a label.

I have the dropdown list #1 to autopostback to dropdown list #2 that "Is supposed to get" another title and value based on the GUID value of the first dropdown list. 

for some reason it wont return anything. I have done 100's of these but never based off a guid value.

I assume the value needs to be converted to guid before selecting it in the second dropdown list.

How can I do this? or is there something I am missing?


I am experiencing an unexpected problem, and I am hoping someone here can help.  I am trying to create a cascading dropdown list using two dropdown lists in Visual Studio 2008 Professional connecting to a SQL Server 2008 Standard database on my local machine.  I have added the two dropdown lists, as well as a CascadingDropDown extender from the AJAX Control Toolkit that corresponds with the first dropdown list.  The problem I am running into is that despite the fact that I have a CascadingDropDown extender for the first dropdown list so far, and the extender is configured properly, the first dropdown list is showing Unbound in Design view.  I also don't see a TargetControlID entry in the properties window for the extender.  I hard coded the TargetControlID to the extender in the Source view and, although I am not receiving any dynamic errors from the TargetControlID entry (meaning, the TargetControlID is a valid parameter, and the dropdown list I entered for that parameter exists on the same page), the dropdown list doesn't populate properly and when in Design view, not only do I not see an entry for the CascadingDropDown extender, but the target dropdown list shows as being "Unbound."

A couple of things I want to point out first:

1) I am using Master pages on this site for the header, footer and navigation.  The opening and closing <form> tags, as well as the <ScriptManager> entry are in the Master page, not the content pages.  I did this with the assumption that at runtime, each page would have the proper <form> tags and <ScriptManager> entry to function properly.

2) I have been able to add a CascadingDropDown extender to a page in Design view (and it initially displays properly), but by the time I have added all of the properties settings to apply it to its corresponding dropdown list, the entry appears normal in Source view but no longer appears in Design view.

When I run the page, the dropdown list does not populate.  Obviously, I assume that this is related to the dropdown list showing in Design view as being Unbound, but I don't know how to get the dropdown list to recognize that I have a CascadingDropDown extender that is supposed to apply to it.

Here is what the two elements look like in Source view:

<asp:DropDownList ID="ddlCompany" runat="server">
            <ajaxToolkit:CascadingDropDown ID="cddCompanies" runat="server" TargetControlID="ddlCompany" Category="Company" PromptText="Select a Company" LoadingText="Please Wait..." ServicePath="~/CompaniesService.asmx" ServiceMethod="GetCompanies">

To create these, I have been following Joe Stagner's example in his video on the topic (http://www.asp.net/ajax/videos/use-aspnet-ajax-cascading-drop-down-control-to-access-a-database) virtually word for word.  I have set up a TableAdapter/DataSet, one for the dropdown list, and the dataset is able to accurately pull the appropriate data from the database, so I know it is working properly.  I believe the problem is that the dropdown list isn't binding with the CascadingDropDown extender properly.  It wouldn't bother me that I don't see a TargetControlID entry in the properies window for the CascadingDropDown extender, although I have a feeling that the absense of that property is related to the fact that the dropdown list is not binding to the extender.

I don't think the content of the CompaniesService.asmx.cs file dictates whether the dropdown list displays Bound versus Unbound, but here is the CompaniesService.asmx.cs file for reference:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using AjaxControlToolkit;
using System.Data;
using System.Data.SqlClient;

namespace AS_Admin
    /// <summary>
    /// Summary description for CompaniesService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    public class CompaniesService : System.Web.Services.WebService

        public CascadingDropDownNameValue[] GetCompanies(string knownCategoryValues, string category)
            dsCompaniesTableAdapters.CompanyTableAdapter companyAdapter = new dsCompaniesTableAdapters.CompanyTableAdapter();
            dsCompanies.CompanyDataTable companies = companyAdapter.GetAllCompanies();
            List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
            foreach (DataRow dr in companies)
                string comp = (string)dr["CompanyName"];
                string compID = (string)dr["CompanyID"];
                values.Add(new CascadingDropDownNameValue(comp, compID));
            return values.ToArray();

I searched online for causes to this problem, but I wasn't able to find any solutions.  If anyone can help me, I would greatly appreciate it.

Thanks in advance.

I have a webpart, that contains:

first a fileupload

below a dropdown, when the value changes the next dropdown will bee showed :).

now when i select a file that must be upload and i change my first dropdown.

the will be refreshed, and the value from the upload file will be empty again.

is there any solution that the webpart wont refresh, and my selected upload file text won't disapear.



Hi friends,

               I had retrieved only column names from a sql server database view using the following query


SqlCommand cmd = newSqlCommand("select column_name from information_schema.columns where table_name='Customers'", con);

Now, I want to display each column name one by one in a dropdownlist..How it is possible? pls help me


Can someone walk me through this?  I'm not a geek so be kind. 

We have a report in spreadsheet format in which we have two separate dropdown lists in two different cells that need to interact.  One lists numbers with the corresponding names, the other is by name first with the corresponding number; think route numbers and names.  We want to be able to use either dropdown, click a selction that will match-up with the other cell, can be saved as is, or changed as needed to update the report.  Need to do this in Excel 2003 & 2007.


When using a term set, is there any way to add a column to a list, using a term set, but have it show up as a dropdownlist or a listbox?


On a MOSS site with the Publishing module enabled I'm experiencing some weird rendering issues with dropdown lists for Lookup fields in edit mode. When clicking the dropdown to select a value, the dropdown pops up somewhere entirely different on the page. I have googled this thoroughly but haven't really found any good solutions to this problem yet.
I understand that SharePoint changes how a dropdown is rendered when the number of items is more than 20, but I'm still hoping that this issue can be fixed in the masterpage and/or stylesheet?

Any thoughts and/or solutions?


So, I have had a look through the other posts and have seen a few questions that appear to be similar, but nothing that really seems to answer what I am sure is a very simple answer (with me just being stupid)!!!!!

If going to the settings and changing theme on the emulator, when selecting 'background', I click on what appears to be a TextBox, this then expands to show multiple options with the curent selection highlighted in the accent colour.

Is this a standard control, or a mix of a couple of controls such as TextBox and ListBox?  I have seen talk of a ListPicker in some of the documentation, which I believe to be the correct control, but this is not available within the tool set.

What has anyone else done to achieve this, or is it something that should be added to the 'to do' list for when the final version is available


Hi there, I need to put a dropdown list inside a prompt box. Would it be possible? If not, what should I do to achieve similar results? I am only able to use Javascript.



I have a textbox and a dropdownlist.

EG. Textbox is to key in patient's name, dropdownlist to select Name. Then it come out with the patient's details of gridview/details view.

I need help badly for this.





Im having a problem to update my value under dropdownlist.

i edit the item to Y AND N.

But it cannot be updated when Ive choosen either one

do you know any way to solve it?





I have created external content types for Customer and City tables in Sharepoint Designer 2010 and then create Customer external list from it. At the time of addition and and edition of item i want to show dropdown field of City instead of external item picker control.


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure