• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Get control of your email attachments. Connect all your Gmail accounts and in less than 2 minutes, Dokkio will automatically organize your file attachments. You can also connect Dokkio to Drive, Dropbox, and Slack. Sign up for free.


Menu Case Study Part 4 - Generating a Javascript call from a Razor Object

Page history last edited by Dr. Ron Eaglin 4 years, 3 months ago

Generating a Javascript call from a Razor Object






Lecture - Menu Case Study Part 2 - Creating a Custom View


Part of Case Study - Menu Example 


Next Lecture - Menu Case Study Part 5 - Ajax Calls




Demonstrates how to create a drop down list in Razor and then call a javascript function from the generated Razor





Reference Materials



@model MenuDatabaseCOP4709.Models.Menu



    ViewBag.Title = "FullDetails";



<script type="text/javascript">

    function selectMenuGroup() {

        var dd = document.getElementById("MenuGroup");

        var index = dd.selectedIndex;

        var value = dd.options[index].value;

        var text = dd.options[index].text;

        alert(index + " : " + value +" : " + text);









    <hr />

    <dl class="dl-horizontal">


            @Html.DisplayNameFor(model => model.MenuTitle)




            @Html.DisplayFor(model => model.MenuTitle)




            @Html.DisplayNameFor(model => model.MenuDescription)




            @Html.DisplayFor(model => model.MenuDescription)




            Select a Menu Group




            @Html.DropDownList("MenuGroup", new SelectList(Model.MenuGroups,

                "MenuGroupId", "MenuGroupTitle"),

                new { onchange = "selectMenuGroup()" })









    @Html.ActionLink("Edit", "Edit", new { id = Model.MenuID }) |

    @Html.ActionLink("Back to List", "Index")





Add code to MenusController.cs

 public ActionResult FullDetails(int? id)


            if (id == null)


                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);


            Menu menu = db.Menus.Find(id);

            if (menu == null)


                return HttpNotFound();


            return View(menu);







Additional Information



COP 4834 Lectures Page

Comments (0)

You don't have permission to comment on this page.