0

I have a Html.ListBox and upon selecting an Item I would like it to pass the item Id in so that I can call and load that selected Item's Information. Whats the best way to pass this id in to a script or maybe is there another way?

     @Html.ListBox("ListBoxName", new SelectList((IEnumerable<Epic>)ViewData["selectedestimate"], "Id", "Name"), new {@class = "ListBoxClass"})



        <script type="text/javascript">
        $(function () {
            $(".ListBoxClass").click(function (event) {
        event.preventDefault(); // Stop the browser from redirecting as it normally would
        $("#editid").load(this.href, function (response) {
            alert('hello'); //this just for testing
        });
    });
});

1 Answer 1

0

I don't think you need to pass it to the function, you should just be able to do this:

$(this).find("option:selected").val();
Sign up to request clarification or add additional context in comments.

3 Comments

How does it know what 'this' to refer to?
nvm that was a dumb question. Thanks this is what I was looking for.
Let me ask you this..how can I get the selected Items Name instead of the Id, or in other words how can I get the properties of whats in my ViewData in the script? Thx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.