Click here to Skip to main content
Rate this: bad
good
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 1:34am
Edited 9-Jan-13 1:35am
v2

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

  Print Answers RSS
0 Mathew Soji 274
1 BillWoodruff 270
2 Afzaal Ahmad Zeeshan 244
3 Sergey Alexandrovich Kryukov 240
4 Raul Iloc 160
0 OriginalGriff 6,219
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,103
3 Manas Bhardwaj 4,549
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2014
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