Read Control DropDownList from View Within the Vie

2019-08-08 06:21发布

问题:

VS '12 asp.net C# mvc Internet App + Kendo UI , EF Code First, Kendo UI

Using Kendo DDL

 @(Html.Kendo().DropDownList()
          .Name("dropdownlist")
          .BindTo(new string[] { "Leasehold A", "Mineral Owner", "Prospect", "StrangerInTitleNote", "StrangerInTitleNoteInfo", "StrangerLeasingNote", "StrangerLeasingNoteInfo", "Subject To", "Surface Note", "Surface Note Info", "Unreleased Mortage", "Unreleased Oil and Gas Leasors", "Vesting Note" })
          )

Very simple right? - now i want to extract the selected Item and place it into an Actionlink

@Html.ActionLink("Create New", "Create", new { id =  } )', null) ....

what do I place at the id= spot. How can I get this to work. Thanks for any answers. PS: Not familiar with MVC to much or any HTML so far, must I use a Script? - preferably I would like to not leave the view.

回答1:

I do it like this. May not be the best but it works for me.

Here is the link:

@Html.ActionLink("Click Me", "YourAction", new { controller = "YourController"}, new       {id="YourActionLinkName"})

The .click function

$('#YourActionLinkName').click(function (e) {


            var val = $("#dropdownlist").val();
            var href = "/YourApp/YourController/YourAction/" + val;
            this.href = ""; //clears out old href for reuse
            this.href = href; //changes href value to currently slected dropdown value

        });