user469652
user469652

Reputation: 51321

ASP.NET MVC: How to post dropdown box value to action?

@using (Html.BeginForm("Index", "Bill"))
{
    @Html.Label("FromDate")
    @Html.DropDownList("FromDate",Model.DateList)
    @Html.Label("ToDate")
    @Html.DropDownList("ToDate", Model.DateList)
    @Html.ActionLink("Filter", "Index", "Bill")            // I want to post to Index 
}

    [HttpPost]
    public ActionResult Index(string fromDate, string toDate)
    {
        //Process
    }

What is the correct way to post the date range to Index action?

What kind of URL do I need to specify?

I appreciate your answers.

Upvotes: 0

Views: 898

Answers (1)

Shawn Mclean
Shawn Mclean

Reputation: 57469

Your @Html.ActionLink("Filter", "Index", "Bill") is just an anchor tag. You need to have a submit button:

<input type="Submit" />

I think thats all you need to submit your 2 values. The submit button uses the POST method that is automatically specified in your Html.BeginForm()

Upvotes: 1

Related Questions