views:

49

answers:

2

I have need of a simple view that let's the user set the date of something. In MVC I can pass the date via ViewData. I want to use the asp:Calendar control (I think). Should I instantiate the control and pass the entire control via ViewData or can I make it in the view and just pass a date over? Once the user is OK with the date will it just POST over in my form? How do I get the value out once POSTed? Do I need to use the whole runat='server' thing if I am only just POSTing?

Sample code appreciated.

A: 

Hey,

If you want to use web forms controls, you have to setup the view as a web form (form runat="server" and each control use runat="server") and you can pass in the view using:

' />

Not used ASP.NET controls much, so I don't know all of the particulars, but I think that might be all you need. Alternatively, you can use web form pages in your MVC app, so you could also just setup this specific page as a web form.

See more here: http://www.packtpub.com/article/mixing-asp.net-webforms-and-asp.net-mvc

Alternatively, check out client-side implementations, because I think there may be a JQuery one.

Lastly, Telerik ASP.NET MVC framework is coming out with a calendar that's due in march; this is open source.

HTH.

Brian
A: 

Server controls are probably out, since you are using ASP.NET MVC, but here is a jQuery plugin that will accomplish the same thing:

http://docs.jquery.com/UI/Datepicker

Here is an example of the plugin in action:

http://jqueryui.com/demos/datepicker/

Robert Harvey