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 7649699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:02:17+00:00 2026-05-31T11:02:17+00:00

I’ve been trying to implement the code in the answer here Issues are:- Setting

  • 0

I’ve been trying to implement the code in the answer here

Issues are:-

  1. Setting up or creation of helper
  2. integrating helper onto view to perform CascadingDropDropListFor

At 1st I tried making a new class for the helper then I instead moved the code into my existing model for the page but found if I did that it solved the issue 2 just to say I couldn’t nest the public static class into my public class StudentViewModel.

To solve issue 1 I tried inputing as many “Using” as needed to get all the code to work and then I found that Web.Mvc.Html was meant to resolve it but didn’t and caused another error.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;

I did find that

using System.Web.WebPages.Html;

Solved the Html.SelectExtension issue which you can see the error below

The name ‘Html’ does not exist in the current context

But caused

‘SelectListItem’ is an ambiguous reference between
‘System.Web.Mvc.SelectListItem’ and
‘System.Web.WebPages.Html.SelectListItem’

Below you can see the helper code which was suggested but I think I must be doing something wrong at some stage to keep causing these different errors to pop up.

            public static class MvcHtmlExtensions
    {
        public static MvcHtmlString CascadingDropDownListFor<TModel, TProperty>(
            this HtmlHelper<TModel> htmlHelper,
            Expression<Func<TModel, TProperty>> expression,
            IEnumerable<SelectListItem> selectList,
            string optionLabel,
            IDictionary<string, Object> htmlAttributes,
            string parentControlName,
            string childListUrl
            )
        {
            var memberName = GetMemberInfo(expression).Member.Name;
            MvcHtmlString returnHtml = Html.SelectExtensions.DropDownListFor(htmlHelper, expression, selectList, optionLabel, htmlAttributes);
            var returnString = MvcHtmlString.Create(returnHtml.ToString() +
                @"<script type=""text/javascript"">
                    $(document).ready(function () { 
                        $(""#<<parentControlName>>"").change(function () {                                  
                            var postData = { <<parentControlName>>: $(""#<<parentControlName>>"").val() };                                 
                            $.post('<<childListUrl>>', postData, function (data) {                                     
                                var options = """";                                     
                                $.each(data, function (index) {                                         
                                    options += ""<option value='"" + data[index].Id + ""'>"" + data[index].Name + ""</option>"";                                     
                                });                                     
                                $(""#<<memberName>>"").html(options);                                 
                            })                                 
                            .error(function (jqXHR, textStatus, errorThrown) { alert(jqXHR.responseText); });                             
                        });                         
                    });                      
                </script>"
                .Replace("<<parentControlName>>", parentControlName)
                .Replace("<<childListUrl>>", childListUrl)
                .Replace("<<memberName>>", memberName));
            return returnString;
        }
        private static MemberExpression GetMemberInfo(Expression method)
        {
            LambdaExpression lambda = method as LambdaExpression;
            if (lambda == null)
                throw new ArgumentNullException("method");
            MemberExpression memberExpr = null;
            if (lambda.Body.NodeType == ExpressionType.Convert)
            {
                memberExpr = ((UnaryExpression)lambda.Body).Operand as MemberExpression;
            }
            else if (lambda.Body.NodeType == ExpressionType.MemberAccess)
            {
                memberExpr = lambda.Body as MemberExpression;
            }
            if (memberExpr == null)
                throw new ArgumentException("method");
            return memberExpr;
        }
    }
}

Otherwise if anybody knowns of a much simpler way of implementing cascading dropdown lists in mvc3 I’ll try that out instead but I’ve already been looking at a bunch of other search results for it and this had been the one I had figured easiest to implement.

Anyway any help would be much appreciated.

  • 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-31T11:02:18+00:00Added an answer on May 31, 2026 at 11:02 am

    use the AjaxDropdown from http://awesome.codeplex.com and you won’t need to write javascript anymore

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.