Go Back   SitePoint Forums > Forum Index > Program Your Site > .NET
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Nov 8, 2009, 07:28   #1
NAWA-mark
Regular
 
NAWA-mark's Avatar
 
Join Date: Aug 2007
Location: Pennsyltucky
Posts: 675
Dabbling in MVC

I'm looking to get deeper into MVC and began dabbling a bit. Am I correct in thinking that to access a server control you choose "convert to web application" which creates the designer files? Is there any downside to taking this step?

Of course adding a server control to an MVC app adds the viewstate to the page. Is that inappropriate for an MVC app?
NAWA-mark is online now   Reply With Quote
Old Nov 8, 2009, 08:27   #2
wwb_99
Community Advisor
SitePoint Award Recipient
 
wwb_99's Avatar
 
Join Date: May 2003
Location: Washington, DC
Posts: 9,134
MVC apps really don't do server controls--it doesn't have the framework bits (like ViewState and page events) they ride upon.
wwb_99 is offline   Reply With Quote
Old Nov 8, 2009, 12:14   #3
NAWA-mark
Regular
 
NAWA-mark's Avatar
 
Join Date: Aug 2007
Location: Pennsyltucky
Posts: 675
Quote:
Originally Posted by wwb_99 View Post
MVC apps really don't do server controls--it doesn't have the framework bits (like ViewState and page events) they ride upon.
Yeah, that's why I'm wondering. You can convert to a web app and then you can use the server controls on the pages you need them. I just wondered because I do need a calendar control so it will be useful to be able to add server controls from time to time.

Convert to web app and then add a <form runat="server"> and you get viewstate. Is that a mortal sin in the MVC arena?
NAWA-mark is online now   Reply With Quote
Old Nov 8, 2009, 12:26   #4
Serenarules
SitePoint Wizard
 
Serenarules's Avatar
 
Join Date: Dec 2002
Posts: 1,013
Mortal sin?

NAWA, something I've learned from my time here is that if it works, and satisfies a requirement, do it.

Patterns, best practices, and all that stuff don't amount to a hill of beans if you cannot do what you need to do.

Just my two cents.
Serenarules is online now   Reply With Quote
Old Nov 8, 2009, 12:35   #5
NAWA-mark
Regular
 
NAWA-mark's Avatar
 
Join Date: Aug 2007
Location: Pennsyltucky
Posts: 675
Quote:
Originally Posted by Serenarules View Post
... Patterns, best practices, and all that stuff don't amount to a hill of beans if you cannot do what you need to do. ...
I agree, just wondered if it defeated the purpose of using MVC if I'm just going to want to use server controls anyway. I can't imagine not using listViews.
NAWA-mark is online now   Reply With Quote
Old Nov 8, 2009, 15:09   #6
Serenarules
SitePoint Wizard
 
Serenarules's Avatar
 
Join Date: Dec 2002
Posts: 1,013
There's a much better way to make lists anyway. Use the following html helper:

Csharp Code:
public static void RenderPartials(this HtmlHelper helper, string partialViewName, IEnumerable models)
{
 foreach (var model in models)
 {
  helper.RenderPartial(partialViewName, model);
 }
}

Put it in a public static class, and then in your page:

Csharp Code:
<ul>
<%Html.RenderPartials("partialName", Model.Items);%>
</ul>

Where the partial (mvc version of a control) is:

<li><%=Model.Field%></li>

Anyway, take a look at how partials and html extensions work, and I think you'll find that you'll be able to not only do what you want, but all without viewstate, and WebForm oddities.
Serenarules is online now   Reply With Quote
Old Nov 8, 2009, 16:25   #7
NAWA-mark
Regular
 
NAWA-mark's Avatar
 
Join Date: Aug 2007
Location: Pennsyltucky
Posts: 675
Well, that is mighty interesting. Any gotchas in nesting lists?

I actually do make rather heavy use of the calendar control. That's still an issue.
NAWA-mark is online now   Reply With Quote
Old Nov 8, 2009, 17:52   #8
Serenarules
SitePoint Wizard
 
Serenarules's Avatar
 
Join Date: Dec 2002
Posts: 1,013
Using the same technique, you could roll your own extremely quickly. Image a single line in your page...

<% Html.RenderCalender(Model.Year); %>

Where your helpers looks like this:

public static string RenderCalendar(this HtmlHelper helper, Year year);

public static string RenderMonth(this HtmlHelper helper, Month month);

public static string RenderWeek(this HtmlHelper helper, Week week);

public static string RenderDay(this HtmlHelper helper, Day day);

Based on a Year having many Months, having many Weeks, having many Days...

Just have each loop and call the next, starting new rows when needed, and other standard calendar things. You could even change the first one to accept some flags for mini-calendars and paging...

public static string RenderCalendar(this HtmlHelper helper, Year year, bool showMini, bool allowPaging);

Good luck.
Serenarules is online now   Reply With Quote
Old Nov 8, 2009, 17:53   #9
NAWA-mark
Regular
 
NAWA-mark's Avatar
 
Join Date: Aug 2007
Location: Pennsyltucky
Posts: 675
Quote:
Originally Posted by Serenarules View Post
Using the same technique, you could roll your own extremely quickly. Image a single line in your page...

<% Html.RenderCalender(Model.Year); %>

Where your helpers looks like this:

public static string RenderCalendar(this HtmlHelper helper, Year year);

public static string RenderMonth(this HtmlHelper helper, Month month);

public static string RenderWeek(this HtmlHelper helper, Week week);

public static string RenderDay(this HtmlHelper helper, Day day);

Based on a Year having many Months, having many Weeks, having many Days...

Just have each loop and call the next, starting new rows when needed, and other standard calendar things. You could even change the first one to accept some flags for mini-calendars and paging...

public static string RenderCalendar(this HtmlHelper helper, Year year, bool showMini, bool allowPaging);

Good luck.
But it's already done with <asp:calendar> and I'm lazier than you are.

Edit - it doesn't really look all that complicated: http://www.codeproject.com/KB/aspnet...-calendar.aspx

Hmmm... interesting.
NAWA-mark is online now   Reply With Quote
Old Nov 8, 2009, 18:13   #10
Serenarules
SitePoint Wizard
 
Serenarules's Avatar
 
Join Date: Dec 2002
Posts: 1,013
Yes, by the title alone (ASP.NET MVC Calendar by extending the HtmlHelper) I can see it is an example of exactly what I was talking about. Two things to note however:

1) Unless his package offers code and ascx templates, and not just a binary, then your level of customization will go down.

2) In the sections where he uses in-line code nuggets to initialize "allPosts" and "dateArray"...just don't do that. Use a highly typed View and pass in a thin presentation class that holds any pre-prepared data you may need. In your controller action:

// set allPosts here
// set dateArray here

return View(new ShowCalendarPresentation(){
AllPosts = allPosts,
DateArray = dateArray
});
Serenarules is online now   Reply With Quote
Old Nov 8, 2009, 18:30   #11
NAWA-mark
Regular
 
NAWA-mark's Avatar
 
Join Date: Aug 2007
Location: Pennsyltucky
Posts: 675
Quote:
Originally Posted by Serenarules View Post
... 1) Unless his package offers code and ascx templates, and not just a binary, then your level of customization will go down. ...
No binary, just class files.

Quote:
Originally Posted by Serenarules View Post
2) In the sections where he uses in-line code nuggets to initialize "allPosts" and "dateArray"...just don't do that. Use a highly typed View and pass in a thin presentation class that holds any pre-prepared data you may need.
I'm sure that was just for quick demonstration purposes. Duly noted. I intended to get into MVC earlier this year but I had to go make money instead. I've got so much to learn.
NAWA-mark is online now   Reply With Quote
Old Nov 8, 2009, 20:05   #12
NAWA-mark
Regular
 
NAWA-mark's Avatar
 
Join Date: Aug 2007
Location: Pennsyltucky
Posts: 675
Now that I look at that MVC calendar I like it probably even better than the server control. It's easily modified and gives me ideas to replace other things I thought necessary.
NAWA-mark is online now   Reply With Quote
Old Nov 9, 2009, 07:25   #13
wwb_99
Community Advisor
SitePoint Award Recipient
 
wwb_99's Avatar
 
Join Date: May 2003
Location: Washington, DC
Posts: 9,134
For 99% of controls one used to use, best bet is to look for jquery plugins. For example, there are a bunch of really slick calendar controls that one can choose from for most desired effects.
wwb_99 is offline   Reply With Quote
Old Nov 9, 2009, 12:43   #14
NAWA-mark
Regular
 
NAWA-mark's Avatar
 
Join Date: Aug 2007
Location: Pennsyltucky
Posts: 675
Quote:
Originally Posted by wwb_99 View Post
For 99% of controls one used to use, best bet is to look for jquery plugins. For example, there are a bunch of really slick calendar controls that one can choose from for most desired effects.
I see. There are some rather nice calendar plugins for jQuery. How would I handle a fallback if javascript is disabled? The event calendar is a major part of most of my sites and I'm not sure it should be scripted on the client side.
NAWA-mark is online now   Reply With Quote
Old Nov 9, 2009, 13:27   #15
wwb_99
Community Advisor
SitePoint Award Recipient
 
wwb_99's Avatar
 
Join Date: May 2003
Location: Washington, DC
Posts: 9,134
They tend to grow out of text boxes, so, at the end of the day, a user should be able to input a date/time value and it will work.
wwb_99 is offline   Reply With Quote
Old Nov 9, 2009, 13:39   #16
NAWA-mark
Regular
 
NAWA-mark's Avatar
 
Join Date: Aug 2007
Location: Pennsyltucky
Posts: 675
Quote:
Originally Posted by wwb_99 View Post
They tend to grow out of text boxes, so, at the end of the day, a user should be able to input a date/time value and it will work.
Oh, I see what you're saying. We're on two different wavelengths here. You mean the calendar extender in the AjaxToolkit, right?

I mean an event calendar like this: http://newcastlechurchofChrist.com/calendar

It uses an <asp:Calendar> and the new version (not yet uploaded) uses an <asp:ListView> for the event list below the calendar. It's a rather major part of the site, if you were logged in you'd see more events, birthdays, anniversaries and such. I don't know that I should leave it up to client side scripting even though I do like this: http://arshaw.com/fullcalendar/
NAWA-mark is online now   Reply With Quote
Old Nov 9, 2009, 13:54   #17
NAWA-mark
Regular
 
NAWA-mark's Avatar
 
Join Date: Aug 2007
Location: Pennsyltucky
Posts: 675
Quote:
Originally Posted by Serenarules View Post
There's a much better way to make lists anyway. Use the following html helper:
...
Anyway, take a look at how partials and html extensions work, and I think you'll find that you'll be able to not only do what you want, but all without viewstate, and WebForm oddities.
I see where you're coming from but I'm wondering if this will do what a listview will do. Paging, sorting, modifying data?
NAWA-mark is online now   Reply With Quote
Old Nov 9, 2009, 14:36   #18
wwb_99
Community Advisor
SitePoint Award Recipient
 
wwb_99's Avatar
 
Join Date: May 2003
Location: Washington, DC
Posts: 9,134
Quote:
Originally Posted by NAWA-mark View Post
Oh, I see what you're saying. We're on two different wavelengths here. You mean the calendar extender in the AjaxToolkit, right?

I mean an event calendar like this: http://newcastlechurchofChrist.com/calendar

It uses an <asp:Calendar> and the new version (not yet uploaded) uses an <asp:ListView> for the event list below the calendar. It's a rather major part of the site, if you were logged in you'd see more events, birthdays, anniversaries and such. I don't know that I should leave it up to client side scripting even though I do like this: http://arshaw.com/fullcalendar/
Gotcha. Well, I think that is a decision best taken by looking at your current userbase, etc. If you see people using IE3 without javascript, then you gotta cater to em . . .
wwb_99 is offline   Reply With Quote
Old Nov 10, 2009, 16:20   #19
NAWA-mark
Regular
 
NAWA-mark's Avatar
 
Join Date: Aug 2007
Location: Pennsyltucky
Posts: 675
Quote:
Originally Posted by wwb_99 View Post
Gotcha. Well, I think that is a decision best taken by looking at your current userbase, etc. If you see people using IE3 without javascript, then you gotta cater to em . . .
Well, we do have some folks on 200MHz PowerComputing Mac clones running OS 8. IE3 may not be as far fetched as you think.

After spending today with MVC, I'm starting to understand how the parts work together. It sure is a different way of looking at things. I think I like it. I wish I had VS 2008 Pro so I could dig into the tests (I have VS 2008 Standard).
NAWA-mark is online now   Reply With Quote
Old Nov 11, 2009, 05:54   #20
wwb_99
Community Advisor
SitePoint Award Recipient
 
wwb_99's Avatar
 
Join Date: May 2003
Location: Washington, DC
Posts: 9,134
That shouldn't stop you--just use nUnit or mbUnit, both of which feature their own test runners. And make sure to grab TestDriven.NET to tie it all together.
wwb_99 is offline   Reply With Quote
Old Nov 11, 2009, 07:38   #21
NAWA-mark
Regular
 
NAWA-mark's Avatar
 
Join Date: Aug 2007
Location: Pennsyltucky
Posts: 675
Quote:
Originally Posted by wwb_99 View Post
That shouldn't stop you--just use nUnit or mbUnit, both of which feature their own test runners. And make sure to grab TestDriven.NET to tie it all together.
I was just coming back to ask if I could run a third-party test suite. Thanks.
NAWA-mark is online now   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 19:20.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved