asp.net-mvcasp.net-mvc-4razorhtml-helper

Html.BeginForm is not working


I want to take textbox value and i will download an excel list according to that value. This is my view:

@using (Html.BeginForm("DownloadAttendeeExcel", "Attendee", FormMethod.Post, new { id = "downloadAttendee", @class = "stdform" }))
 {        <div>
            @Html.TextBoxFor(x => x.EventID, new { id = "eventID" })
        </div>       
       <div>
       @Html.TextBoxFor(x => x.EventName, new { id = "eventName" })
        </div>

 }

This is my action but i can't set model.eventID according to textbox value and i can't understand why.

public ActionResult DownloadAttendeeExcel(AttendeeListItem model)
        {
            Reservation res = new Reservation();
            res.EventID = model.EventID;
            return View();
        }

Solution

  • Your button :

    <a class="btn" type="button" id="downloadAttendees" ref="@Url.Action("DownloadAttendeeExcel", "Attendee")" style="width: 150px;">
    

    Will perform an HttpGet and will not post your form data.
    The simplest way to instruct your form to submit it's content(all the input fields it contains) is to use a html submit button :

    <input type="submit" value="Submit">