I have 2 questions (totally unrelated) about the mvc framework. I've only read about it. I haven't installed any of the requirements to use mvc (vs08, mvc bits/ext.)
<div mce_keep="true">So far all the online examples demonstrate passing single entities to the controler. What if I need a collection of items, along with a string, or date?
Example: I have a text box and a multi-select list box. Could my controler function look like this? public void DoSomething(string text, IEnumerable<int> selectedValues) { }</div>
<div mce_keep="true">Along those lines what would the markup language look like (true html, not asp controls)?</div>
<div mce_keep="true">What are devleopers using for calendar controls? If/When i switch to the MVC framework I would like to abandon server controls with runat="server" attributes and use pure html. Right now I am completely at the mercy of asp.net controls
for GUI development. I use BasicDatePicker for date selection and would want a similar control for MVC. Prototype has a calendar control, the CSS wasn't great, but you could page months and select dates.
what other calendars exist? Note: I'm not looking for the full functionality of BDP, it's a rather heavy control. really i would just want something that ensure real dates are entered and gives the user a calendar to look at.</div>
I believe my questions stem from the fact that I rely very heavly on asp.net and no very little about REST, html, js. There's always something new to learn:)
1) I was going to say you could do this with the MVCContribs ConventionController. Simply inherit from ConventionController and apply the Deserialise attribute to your argument. like:
public void SomeAction(string text, [Deserialise("prefix")] List<int> selectedValues)
but then i looked at it and you can't. that expects array and list types to be in prefix[0]. prefix[1] format but this is just a single field passing back a comma separated list of ints. If they're listening maybe they'll fix it so this works?!?
the easieast way to do this is just SomeAction(string, string) and split the selectedValues by comma.
2) this doesn't require any special markup, the only thing you need to think about is the naming of the form elements.
3) don't be afraid of runat=server. There's probably going to be a calendar control in the suite of controls that come with the MVC Framework when it ships. you can actually currently use the old asp.net controls on your forms, but because you've lost postback
they're only good for rendering html (which they typically don't do very well imho)
I agree the markup for server controls is limited at best.
so I could create a form tag without the runat attribute and still use <asp:TextBox runat="server" id="foo" /> ? This I did not know. Comes back to my limited knowledge of html. Using server controls still renders the ulgy ClientID correct?
yes, there are a lot of classic controls that don't need a <form runat="server">
and, no, because you're not using webforms you don't get any of that ctrl12$... rubbish, just the plain old ClientId == Id semantics
you don't have postback, so none of the events of the texbox fire, and you can't reference the Textbox in the controller to do Textbox1.Text or anything like that. they are purely for rendering html.
The Web Server Controls will genereate a unique Id, the rendering process of the Contorls aren't changed. You can also add them into a <form runat="server"> and access them from the code-behind of the View and set some values even if I shouldn't do that.
The TextBox control need to be inside of the <form runat="server">, so some of the original controls need the form tag.
Microsoft will add new controls that will work with the MVC framework, or at least looking at it. We have some sort of helper methods today to create elements.. for example the HtmlHelper class, which has several of extenstion methods added if the MVcToolkit
will be used.
As tgmdbm mention, the Postback will not work correclty. some controls will still do a postback, but the idea is not to use postback.. for example the ViewState will not work correctly etc. The whole thing with the MVC Framework is to use the MVC Pattern
instead of a Web Form postback solution. So no event driven pogramming etc. The Controller has "action" methods that should be called instead and perform some action based on user input etc.
<div class="commentowner">I think this was what he was referring to. looks a bit hacky.
#re: Tip/Trick: Cool UI Templating Technique to use with ASP.NET AJAX for non-UpdatePanel scenarios
<div class="commentssubhead"> Monday, October 23, 2006 10:17 AM by
ScottGu </div>
Hi Steve,
One approach would be to use ASP.NET's HTML intrinsic controls instead of the <asp:> ones for things like buttons and checkboxes. These are easy to use - just add the regular HTML elements to the user control and then add an "ID" attribute and a runat="server".
These won't complain about needing to be in a <form> element.
If you want to use a control that needs to be in a <form> element to render, one approach you could take would be to dynamically inject a form element under the page class (within the RenderView method I built, and then add the UserControl under that). You
could build your own custom derived page class that stripped out the <form> control's rendering output if you wanted - which would then cause you to only return the exact HTML that you need.
<div mce_keep="true">At this point MVC doesn't handle Enumerable<T> in the controller calls. Instea I would need to construct them myself (most likely a comma seperated string)</div>
<div mce_keep="true">For the sake of simplicity asp server controls don't work with MVC. however asp html controls will.</div>
jason_m
Member
283 Points
81 Posts
passing collecions to controler and GUI date picker
Jan 31, 2008 12:48 PM|LINK
I have 2 questions (totally unrelated) about the mvc framework. I've only read about it. I haven't installed any of the requirements to use mvc (vs08, mvc bits/ext.)
Example: I have a text box and a multi-select list box. Could my controler function look like this? public void DoSomething(string text, IEnumerable<int> selectedValues) { }</div>
I believe my questions stem from the fact that I rely very heavly on asp.net and no very little about REST, html, js. There's always something new to learn:)
Programmer
Specialty Bakers, Inc.
tgmdbm
Contributor
4392 Points
883 Posts
ASPInsiders
MVP
Re: passing collecions to controler and GUI date picker
Jan 31, 2008 02:17 PM|LINK
1) I was going to say you could do this with the MVCContribs ConventionController. Simply inherit from ConventionController and apply the Deserialise attribute to your argument. like:
public void SomeAction(string text, [Deserialise("prefix")] List<int> selectedValues)
but then i looked at it and you can't. that expects array and list types to be in prefix[0]. prefix[1] format but this is just a single field passing back a comma separated list of ints. If they're listening maybe they'll fix it so this works?!?
the easieast way to do this is just SomeAction(string, string) and split the selectedValues by comma.
2) this doesn't require any special markup, the only thing you need to think about is the naming of the form elements.
3) don't be afraid of runat=server. There's probably going to be a calendar control in the suite of controls that come with the MVC Framework when it ships. you can actually currently use the old asp.net controls on your forms, but because you've lost postback they're only good for rendering html (which they typically don't do very well imho)
good luck
jason_m
Member
283 Points
81 Posts
Re: passing collecions to controler and GUI date picker
Jan 31, 2008 02:25 PM|LINK
I agree the markup for server controls is limited at best.
so I could create a form tag without the runat attribute and still use <asp:TextBox runat="server" id="foo" /> ? This I did not know. Comes back to my limited knowledge of html. Using server controls still renders the ulgy ClientID correct?
Programmer
Specialty Bakers, Inc.
tgmdbm
Contributor
4392 Points
883 Posts
ASPInsiders
MVP
Re: passing collecions to controler and GUI date picker
Jan 31, 2008 02:35 PM|LINK
yes, there are a lot of classic controls that don't need a <form runat="server">
and, no, because you're not using webforms you don't get any of that ctrl12$... rubbish, just the plain old ClientId == Id semantics
you don't have postback, so none of the events of the texbox fire, and you can't reference the Textbox in the controller to do Textbox1.Text or anything like that. they are purely for rendering html.
jason_m
Member
283 Points
81 Posts
Re: passing collecions to controler and GUI date picker
Jan 31, 2008 02:44 PM|LINK
thanks for the information. this will be helpful when converting to mvc.
Programmer
Specialty Bakers, Inc.
Fredrik N
All-Star
29674 Points
5334 Posts
MVP
Re: passing collecions to controler and GUI date picker
Jan 31, 2008 02:50 PM|LINK
The Web Server Controls will genereate a unique Id, the rendering process of the Contorls aren't changed. You can also add them into a <form runat="server"> and access them from the code-behind of the View and set some values even if I shouldn't do that. The TextBox control need to be inside of the <form runat="server">, so some of the original controls need the form tag.
Microsoft will add new controls that will work with the MVC framework, or at least looking at it. We have some sort of helper methods today to create elements.. for example the HtmlHelper class, which has several of extenstion methods added if the MVcToolkit will be used.
As tgmdbm mention, the Postback will not work correclty. some controls will still do a postback, but the idea is not to use postback.. for example the ViewState will not work correctly etc. The whole thing with the MVC Framework is to use the MVC Pattern instead of a Web Form postback solution. So no event driven pogramming etc. The Controller has "action" methods that should be called instead and perform some action based on user input etc.
MVP, ASPInsider, WCF RIA Services Insider
My Blog
tgmdbm
Contributor
4392 Points
883 Posts
ASPInsiders
MVP
Re: passing collecions to controler and GUI date picker
Jan 31, 2008 03:06 PM|LINK
Oops, he's right, i remember ScottGu saying there is a way to turn it off tho. but a quick search hasn't revealed anything.
if you need to you can always use <input runat="server">
tgmdbm
Contributor
4392 Points
883 Posts
ASPInsiders
MVP
Re: passing collecions to controler and GUI date picker
Jan 31, 2008 03:10 PM|LINK
# re: Tip/Trick: Cool UI Templating Technique to use with ASP.NET AJAX for non-UpdatePanel scenarios
<div class="commentssubhead"> Monday, October 23, 2006 10:17 AM by ScottGu </div>Hi Steve,
One approach would be to use ASP.NET's HTML intrinsic controls instead of the <asp:> ones for things like buttons and checkboxes. These are easy to use - just add the regular HTML elements to the user control and then add an "ID" attribute and a runat="server". These won't complain about needing to be in a <form> element.
If you want to use a control that needs to be in a <form> element to render, one approach you could take would be to dynamically inject a form element under the page class (within the RenderView method I built, and then add the UserControl under that). You could build your own custom derived page class that stripped out the <form> control's rendering output if you wanted - which would then cause you to only return the exact HTML that you need.
Hope this helps,
Scott
</div>jason_m
Member
283 Points
81 Posts
Re: passing collecions to controler and GUI date picker
Jan 31, 2008 03:20 PM|LINK
To sum up:
Programmer
Specialty Bakers, Inc.
MikeBosch
Member
617 Points
127 Posts
Re: passing collecions to controler and GUI date picker
Jan 31, 2008 03:45 PM|LINK
I would recommend looking into some client side calendars. I typically use jQuery for these UI elements:
http://marcgrabanski.com/code/ui-datepicker/
http://weblogs.asp.net/mikebosch
*** Please MARK this post as ANSWERED, if you find it helpful) ***