Click here to Skip to main content
12,947,834 members (88,217 online)
Rate this:
 
Please Sign up or sign in to vote.
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.
Posted 9-Jan-13 0:34am
Updated 9-Jan-13 0:35am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,344
CHill60 3,275
Maciej Los 2,628
Jochen Arndt 1,935
ppolymorphe 1,795


Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100