0

I have a dropdown list like below. Data is bound using viewbag.

<div class="col-md-4">
    <h2 style="color: #2f6207">dfdfDestination</h2>
    @Html.DropDownList("Destination", new SelectList(ViewBag.Destination, "regCde", "Destination", "Destination"))
</div>

Now I want to send the selected value from the dropdown list to a specific controller. I use jQuery and ajax to do this. It sends the value. But while querying value get null. I have no idea. Is there any other way to do this?

public ActionResult MscHome(string mydestination)
{
    return View();
}

1 Answer 1

2

View:

@using (Html.BeginForm("MscHome", "Home", FormMethod.Get)) 
{
    <div class="col-md-4">
        <h2 style="color: #2f6207">dfdfDestination</h2>
        @Html.DropDownList("Destination", new SelectList(ViewBag.Destination, "regCde", "Destination", "Destination"))

    </div>
    <p>
        <input type="submit" value="Submit" />
    </p>

}

Controller:

public ActionResult MscHome(string Destination)
{
    return View();
}

Notice that you have to specify the action and controller on the Html.BeginForm so the view knows where to perform HttpGet or HttpPost and that the name for your dropdownlist value should be equal to the parameter name of your action result in the controller.

Sign up to request clarification or add additional context in comments.

1 Comment

please tell me how to add it.then I can check this

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.