Reputation: 1249
After page loaded, user will give a value to textbox. I want to give that value as parameter to my Action. I am new to MVC and don't know how to do. I know that Html.Textbox name should be same as parameter but i'm conflicted about when i call that action, parameter will be empty so i will take parameter missing error.
This is my html:
@Html.TextBoxFor(x => x.EventID, new { id = "eventID" })
This is my action:
public ActionResult DownloadAttendeeExcel(int eventID)
{
return View();
}
Upvotes: 0
Views: 90
Reputation: 6423
for helpers tie the value of the field to your model. so if on your view you have
@model ViewModel
at the top and EventID is part of that model then change your controller to
public ActionResult DownloadAttendeeExcel(ViewModel model)...
and that will have that value of that text box. Being an id you probably don't want the user to change it so in that case I would put that value in a hidden for
@Html.HiddenFor(x => x.EventID)
so the value passed to the view will be passed back to the controller
Upvotes: 2