Hi guys,
I have just started out with ASP.NET MVC3/4 and I have hit my first wall. I have a model class and a view that is strongly typed to it and obviously a controller. This view has a WebGrid that defines several columns that are bound to the model and 2 date columns (text boxes basically), i.e. Start Date and End Date that are not part of the model class. Finally, there is a ActionLink that when clicked talks to the controller by passing the id of the corresponding record.
Heres where I am stuck now, i also need to pass the start and end dates to the controller but I just can't figure out how to access the date values from the text boxes. I am using jQuery DatePicker widget to select a date in those text boxes but unlike regular ASP.NET there seems to be no way to just do a "txtStartDate.Text" or do a FindControl in a templated column.
My View markup looks like so:
@model IEnumerable<Models.BusinessObject1>
@{
var mvcgrid = new WebGrid(Model);
}
<script type="text/javascript">
$(document).ready(function () {
$("#txtStartDate").datepicker();
$("#txtEndDate").datepicker();
});
</script>
<div id="Grid">
@mvcgrid.GetHtml(columns: mvcgrid.Columns(
mvcgrid.Column("BOName", "Name"),
mvcgrid.Column(null, "Start Date", format: (item) => Html.TextBox("txtStartDate")),
mvcgrid.Column(null, "End Date", format: (item) => Html.TextBox("txtEndDate")),
mvcgrid.Column(format: (item) => Html.ActionLink("Test","Check",new{selectedid =item.ID, startdate = ??, enddate = ??}))))
</div>
I know this sounds pretty MVC101-ish, but I have looked quite a lot and couldn't find something that would help me, may be I haven't looked enough so if anyone can help me with this it will be awesome.
Thanks.