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

  • SEARCH
  • Home
  • 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 4087684
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:53:10+00:00 2026-05-20T18:53:10+00:00

here is my jquery : $(document).ready(function () { $(#GameId).change(function () { $.get(‘/MatchManager/GetMatchType/’ + $(this).val(),

  • 0

here is my jquery :

$(document).ready(function () {

    $("#GameId").change(function () {

        $.get('/MatchManager/GetMatchType/' + $(this).val(), function (response) {

            var Games = $.evalJSON(response);

            var ddlSelectedProduct = $("#MatchTypeId");

            $("#MatchTypeId > option").remove();

            for (i = 0; i < Games.length; i++) {

                ddlSelectedProduct.append($("<option />").val(Games[i].Value).text(Games[i].Text));

            }
        });

    });

});

I print out the response and its correct, but for some reason my program stops at the $.evalJson and says $.evalJSON is not a function Here is my GetMatchType controller just in case:

public string GetMatchType(int id)
    {
        var ListMatchTypes = new List<SelectListItem>();
        using (var db = new MatchGamingEntities())
        {

            var MyMatchTypes = from m in db.MatchTypes
                               where m.GameId == id
                               select m;
            foreach (var item in MyMatchTypes.ToList())
            {
                ListMatchTypes.Add(new SelectListItem() { Text = item.MatchTypeName, Value = item.MatchTypeId.ToString() });
            }
        }
        return new JavaScriptSerializer().Serialize(ListMatchTypes);

    }

This is my view:

@using (Html.BeginForm()) {
@Html.ValidationSummary(true)

MatchModel

@Html.LabelFor(model => model.GameId)

@Html.DropDownList(“GameId”, new SelectList(ViewBag.MyGames as System.Collections.IEnumerable, “GameId”, “GameName”), “Please Select One”)

    </div>
    <div class="editor-label">
        @Html.LabelFor(model => model.MatchTypeId)
    </div>
    <div class="editor-field">
        @Html.DropDownList("MatchTypeId", new SelectList(ViewBag.MatchTypes as System.Collections.IEnumerable, "Value", "Text"))

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

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



    <div class="editor-label">
        @Html.LabelFor(model => model.Wager)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Wager)
        @Html.ValidationMessageFor(model => model.Wager) <br />
        <span>Your Current Account Balance: @ViewBag.Balance</span>
    </div>

    <p>
        <input type="submit" value="Create" />
    </p>
</fieldset>

}

@Html.ActionLink(“Back to List”, “Index”)

  • 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-20T18:53:11+00:00Added an answer on May 20, 2026 at 6:53 pm

    Remarks:

    • Controller actions should always return ActionResults
    • Use JsonResult instead of manually serializing with JavaScriptSerializer
    • You don’t need to manually parse with any $.evalJSON on the client => if you followed my previous remark the proper content type application/json will be sent and jQuery will automatically parse the object passed to the success callback.
    • Never hardocode urls in your javascript => always use url helpers when dealing with urls or your code might break when you deploy due to virtual directory added.

    This being said let’s try to improve your code starting with the controller action:

    public ActionResult GetMatchType(int id)
    {
        using (var db = new MatchGamingEntities())
        {
            return Json(
                from m in db.MatchTypes
                where m.GameId == id
                select new {
                    Text = m.MatchTypeName,
                    Value = m.MatchTypeId
                },
                JsonRequestBehavior.AllowGet
            );
        }
    }
    

    and then the javascript:

    $(function () {
        $('#GameId').change(function () {
            var url = '@Url.Action("GetMatchType", "MatchManager")';
            var data = { id: $(this).val() };
            $.get(url, data, function (games) {
                var ddlSelectedProduct = $('#MatchTypeId');
                ddlSelectedProduct.empty();
                $.each(games, function(index, game) {
                    ddlSelectedProduct.append(
                        $('<option/>', {
                            value: game.Value,
                            text: game.Text
                        })
                    );
                });
            });
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just curious... I begin my jquery code with this: jQuery(document).ready(function($) { /*code here*/ })
I'm using jquery to submit my form (with id #myForm here) as follows: $(document).ready(function()
Here is my jQuery code: $.get('/Home/GetList', function(data) { debugger; $('#myMultiSelect').val(data); }); Here is my
jQuery(document).ready(function($) { $('.c5sliderSelect').change(function() { alert('change clicked'); }); }); When I change the select list
Currently im polling/checking every 1000ms by doing a GET to /moves: jQuery(document).ready(function() { setInterval(function()
Here is the JQuery: $(document).ready(function() { $('#autosave').click(function() { var url = window.location.pathname; $postData =
Here is client Side code: jQuery(document).ready(function(){ jQuery(#list).jqGrid({ url:'example.php', datatype: 'xml', mtype: 'GET', colNames:['Inv No','Date',
Here is the JQGrid setup information jQuery(document).ready(function () { jQuery(#list).jqGrid({ url: '/TabMaster/GetGridData', datatype: 'json',
jQuery(document).ready(function(){ // ok im geting the value here maybe i should make it in
Here's my fiddle: http://jsfiddle.net/mikeritter/prsfM/28/ Here's my jQuery: $(document).ready(function(){ function howdy(n){ alert('Howdy '+n+'!'); } function

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.