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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:37:08+00:00 2026-05-17T15:37:08+00:00

I tried to integrate this javascript mvc sample http://www.alexatnet.com/content/model-view-controller-mvc-javascript into an asp.net page, I’m

  • 0

I tried to integrate this javascript mvc sample http://www.alexatnet.com/content/model-view-controller-mvc-javascript into an asp.net page, I’m complete beginner at jquery and nothing shows up, why ?

Update: I have added missing html listbox but now no javascript seems to execute to initialize the listbox nor the buttons seem to work

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="javascriptmvc01._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <script language="JavaScript" type="text/javascript">

        /**
        * The Model. Model stores items and notifies
        * observers about changes.
        */
        var ListModel = function (items) {
            this._items = items;
            this._selectedIndex = -1;

            this.itemAdded = new Event(this);
            this.itemRemoved = new Event(this);
            this.selectedIndexChanged = new Event(this);
        };

        ListModel.prototype = {

            getItems: function () {
                return [].concat(this._items);
            },

            addItem: function (item) {
                this._items.push(item);
                this.itemAdded.notify({ item: item });
            },

            removeItemAt: function (index) {
                var item = this._items[index];
                this._items.splice(index, 1);
                this.itemRemoved.notify({ item: item });
                if (index == this._selectedIndex)
                    this.setSelectedIndex(-1);
            },

            getSelectedIndex: function () {
                return this._selectedIndex;
            },

            setSelectedIndex: function (index) {
                var previousIndex = this._selectedIndex;
                this._selectedIndex = index;
                this.selectedIndexChanged.notify({ previous: previousIndex });
            }

        };  


        var Event = function (sender) {
            this._sender = sender;
            this._listeners = [];
        };

        Event.prototype = {
            attach: function (listener) {
                this._listeners.push(listener);
            },
            notify: function (args) {
                for (var i = 0; i < this._listeners.length; i++) {
                    this._listeners[i](this._sender, args);
                }
            }
        };

        var ListView = function (model, controller, elements) {
            this._model = model;
            this._controller = controller;
            this._elements = elements;

            var _this = this;

            // attach model listeners
            this._model.itemAdded.attach(function () {
                _this.rebuildList();
            });
            this._model.itemRemoved.attach(function () {
                _this.rebuildList();
            });

            // attach listeners to HTML controls
            this._elements.list.change(function (e) {
                _this._controller.updateSelected(e);
            });

        };


        ListView.prototype = {

            show: function () {
                this.rebuildList();
                var e = this._elements;
                var _this = this;
                e.addButton.click(function () { _this._controller.addItem() });
                e.delButton.click(function () { _this._controller.delItem() });
            },

            rebuildList: function () {
                var list = this._elements.list;
                list.html('');
                var items = this._model.getItems();
                for (var key in items)
                    list.append($('<option>' + items[key] + '</option>'))
                this._model.setSelectedIndex(-1);
            }

        };

        var ListController = function (model) {
            this._model = model;
        };

        ListController.prototype = {

            addItem: function () {
                var item = prompt('Add item:', '');
                if (item)
                    this._model.addItem(item);
            },

            delItem: function () {
                var index = this._model.getSelectedIndex();
                if (index != -1)
                    this._model.removeItemAt(this._model.getSelectedIndex());
            },

            updateSelected: function (e) {
                this._model.setSelectedIndex(e.target.selectedIndex);
            }

        };

        $(function () {
            var model = new ListModel(['PHP', 'JavaScript']);
            var view = new ListView(model, new ListController(model),
        {
            'list': $('#list'),
            'addButton': $('#plusBtn'),
            'delButton': $('#minusBtn')
        }
    );
            view.show();
        });        
    </script>

<select id="list" size="10" style="width: 15em"></select><br/>
<button id="plusBtn">  +  </button>
<button id="minusBtn">  -  </button>
    </div>



    </form>
</body>
</html>
  • 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-17T15:37:09+00:00Added an answer on May 17, 2026 at 3:37 pm

    change:

    <script src="Scripts/jquery-1.4.1.js" type="text/javascript">
    

    to:

    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried to integrate the Picasa API on iPhone, compiles fine, but I
Tried something like this: HttpApplication app = s as HttpApplication; //s is sender of
I tried scouring the web for help on this issue, but there are so
I tried this XAML: <Slider Width=250 Height=25 Minimum=0 Maximum=1 MouseLeftButtonDown=slider_MouseLeftButtonDown MouseLeftButtonUp=slider_MouseLeftButtonUp /> And this
Recently, I was trying to prototype some jQuery-based menu into ASP.NET MVC. Just to
I am developing a http module that hooks into the FormsAuthentication Module through the
I'm trying to write some javascript functions to integrate with the Facebook stream. However
Tried to map it from Preferences -> Settings -> Keyboard, but the key combo
I tried to install Delphi 7 on Vista several times and Vista prevented me
I tried recently to use NAnt (beta 0.86.2962.0) to run some unit tests compiled

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.