asp.net mvc & jquery dialog: What approach do I take to add items to a dropdownlist/select list with

Posted by Mark Redman on Stack Overflow See other posts from Stack Overflow or by Mark Redman
Published on 2010-03-25T09:06:35Z Indexed on 2010/03/25 11:03 UTC
Read the original article Hit count: 272

Hi,

I am new to MVC and have a grasp of the basic model, but still doing everything with postbacks etc.

One aspect of the UI I want to build is to have a drop-down-list of items with a button to add an item to the database and refresh the list. Achieving this with WebForms was straight forward as everything was wrapped in UpdatePanels, but what is the best approach to achieve this using MVC?

Part of the markup for the list and button look like this:

<table>
    <tr>
        <td><%=Html.DropDownList("JobTitleSelectList", Model.JobTitleSelectList, "(select job title)", new { @class = "data-entry-field" })%></td>
        <td>&nbsp;</td>
        <td><a id="AddJobTitleDialogLink" href="javascript: addJobTitleDialog();" title="Add Job Title"><img id="AddJobTitleButtonImage" src="/Content/Images/Icons/16x16/PlusGrey.png" border="0" /></a></td>
    </tr>
</table>

The Dialog is a standard jquery Ui dialog, looks like this:

<div id="SingleTextEntryDialog" style="display:none">
        <table>
            <tr>
                <td>Name:</td>
                <td><input id="SingleTextEntryDialogText" type="text" size="25" /></td>
            </tr>
        </table>
    </div>

I am guessing I need to put this into a UserControl / PartialView (are they the same thing?) Also with the strongly typed View how do I pass the Model or just the SelectList Property to the UserControl or is this not the case?

Nor sure if there should be form in the dialog div? or how that is going to postback via ajax.

Some examples show a lot of ajax code in the page something like: $.ajax({...}); I assume doing this using jquery is more code than asp.net webforms, but there is just more code to see doing a "View Source" on a page?

Your comments appreciated.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about jQuery