开发者

asp:Calendar in an MVC View, preset the date from Controller and Post the value from View?

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 ViewD开发者_JS百科ata 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.


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/


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:

<asp:Calendar ... SelectedDate='<%= Model.Date %>' />

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜