I have a from and to date search box on my view.
This POSTs to my controller, which then searches for available rooms between the dates selected. The results are then listed in the view again.
I’m used to WebForms, where you can PostBack, and grab any control data – however in MVC you can’t do this.
When the results are displayed, how can I then POST back to a controller, both the RoomId that has been selected:
@Html.ActionLink("Book Room","Book", new { id=item.RoomId })
…and the tbFrom and tbTo dates from the TextBoxes?
My view is below.
Thanks for any assistance,
Mark
@model IEnumerable<ttp.Models.Room>
@{
ViewBag.Title = "Avail";
}
<h2>Avail</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
@using (Html.BeginForm())
{
<p>
Availability between @Html.TextBox( "dteFrom" , String.Format( "{0:dd/MM/yyyy}", DateTime.Now) , new { @class = "datepicker span2" } )
and @Html.TextBox( "dteTo" , String.Format( "{0:dd/MM/yyyy}", DateTime.Now) , new { @class = "datepicker span2" } )
<input type="submit" value="Search" /></p>
}
<table class="table table-striped table-bordered table-condensed" style="width:90%" id="indexTable" >
<tr>
<th>
@Html.DisplayNameFor(model => model.RoomName)
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.RoomName)
</td>
...
...
<td>
@Html.ActionLink("Book Room","Book", new { id=item.RoomId })
</td>
</tr>
}
</table>
make your views strongly typed… and to know what strongly typed views are in mvc.net here are a few links
http://www.howmvcworks.net/OnViews/BuildingAStronglyTypedView
What is strongly-typed View in ASP.NET MVC
http://blog.stevensanderson.com/2008/02/21/aspnet-mvc-making-strongly-typed-viewpages-more-easily/
more over if you have the default routes set in your application, in your
POSTaction result you can get theidas the route value likebut from the code what i see is that you are not posting a form, actionlinks make a
GETrequest in that case remove the[HttpPost]action filter from the action result…EDIT
may be i just misunderstood the question… in your current scenario if
ajaxis an option you can do something like thisassign a class to your action links like
now attach a click event handler to it
specify the action name and controller to which the form will be posted
in your controller you will have something like