Why ASP.NET MVC?

A

Author

I happened to see this asp.net MVC tutorial at

http://www.asp.net/learn/mvc/tutorial-01-cs.aspx

Indeed as the author says it is gonna look like classic ASP at the
very beginning of this tutorial.

I think form post with an action (which is classic asp style) like

<form method="post" action="/Home/CreateNew">
the form to be posted goes here.
</form>

is OK to me, but as soon as I see embedded curly braces and ifs and
else's inside <% and %>, I am determined that I wanna stay far from
it.

I think embedding codes inside <% and %> like that of classic ASP and
JSP is notoriously hard to read and difficult to maintain, and error-
prone.

To my understanding, part of struts' functionality is to embedded
codes in JSP. I don't know why people wanna revert back to the old
coding style with asp.net mvc and your input is appreciated.

Or is it the case that such embeddings are not necessary with asp.net
MVC? If yes, then it may be worth looking into a little.

I searched a little in this group and found this:

http://groups.google.com/group/micr...5b2463d5?hl=en&lnk=gst&q=mvc#a2307ade5b2463d5
 
A

Author

I happened to see this asp.net MVC tutorial at

http://www.asp.net/learn/mvc/tutorial-01-cs.aspx

Indeed as the author says it is gonna look like classic ASP at the
very beginning of this tutorial.

I think form post with an action (which is classic asp style) like

<form method="post" action="/Home/CreateNew">
  the form to be posted goes here.
</form>

is OK to me, but as soon as I see embedded curly braces and ifs and
else's inside <% and %>, I am determined that I wanna stay far from
it.

I think embedding codes inside <% and %> like that of classic ASP and
JSP is notoriously hard to read and difficult to maintain, and error-
prone.

To my understanding, part of struts' functionality is to embedded
codes in JSP.  I don't know why people wanna revert back to the old
coding style with asp.net mvc and your input is appreciated.

Or is it the case that such embeddings are not necessary with asp.net
MVC?  If yes, then it may be worth looking into a little.

I searched a little in this group and found this:

http://groups.google.com/group/microsoft.public.dotnet.framework.aspn...

Correction:

<quote>
To my understanding, part of struts' functionality is to embedded
codes in JSP.
</quote>

should read

To my understanding, part of struts' functionality is to get rid of
embedded
codes in JSP.
 
B

bruce barker

casual web developers will probably stay with webforms. you switch to mvc
when any of the following are important enough to switch:

1) you are unit test developer (use test first design)
2) are tried of webforms "fake" and complex event model.
3) are writing lots of javascript and tired of id's changing, and want
standard html components.
4) want better seperation of view and controller code.
5) want a ruby on rails coding experience (mvc is easier with a dynamic
language like ironpython, ironruby or javascript)
6) you are commited to the mvc pattern, and want a supported platform
7) you switched to jQuery (see #3)
8) your web site is going to be large and complex.


-- bruce (sqlwork.com)
 
A

Author

casual web developers will probably stay with webforms. you switch to mvc
when any of the following are important enough to switch:

1) you are unit test developer (use test first design)
2) are tried of webforms "fake" and complex event model.
3) are writing lots of javascript and tired of id's changing, and want
standard html components.
4) want better seperation of view and controller code.  
5) want a ruby on rails coding experience (mvc is easier with a dynamic
language like ironpython, ironruby or  javascript)
6) you are commited to the mvc pattern, and want a supported platform
7) you switched to jQuery  (see #3)
8) your web site is going to be large and complex.

-- bruce (sqlwork.com)

Thank you very much for sharing. Could you say something about the
main disadvantage of ASP.NET MVC?

Also, is there a way to avoid embedding codes inside <% and %>?

Thanks a lot.
 
G

Gregory A. Beamer \(Cowboy\) - MVP

It is very Rails like. It is designed to completely separate UI from
business rules and data access. This works if you just consider the actual
painting of the form UI. If you consider the entire wb application to be UI,
then most of the examples are still doing horrible on separation of
concerns, although the code is not in the actual UI element (whether ASPX or
otherwise).

I am not sure whether MVC will take off. I suspect not until the tools catch
up with the ASP.NET team. After that, I think it will take off, but only
time will tell.

As for the why? ASP.NET needed its rails. ;-)

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
 
J

John Saunders

bruce barker said:
casual web developers will probably stay with webforms. you switch to mvc
when any of the following are important enough to switch:

1) you are unit test developer (use test first design)

Bruce, MVC isn't the only way to do TDD with ASP.NET. Mostly, just don't
allow any business logic on a page, and the largest part of the problem is
solved. There's nothing left after that than pure UI testing.
2) are tried of webforms "fake" and complex event model.
3) are writing lots of javascript and tired of id's changing, and want
standard html components.

There are ways to address the id changing problem. Our product uses huge
amounts of JavaScript, has done for years, and does not have problems with
ids changing. It's not the only product I know of that does so, either.

In fact, you surely cannot be under the impression that during the more than
seven years that ASP.NET has been out there that nobody has been doing
large, complex JavaScript.
4) want better seperation of view and controller code.

Again, many ways to skin that cat.
5) want a ruby on rails coding experience (mvc is easier with a dynamic
language like ironpython, ironruby or javascript)
6) you are commited to the mvc pattern, and want a supported platform
7) you switched to jQuery (see #3)
8) your web site is going to be large and complex.

Our enterprise web applications are very large and complex, and are built
with standard ASP.NET controls, and, again, have done for years.

I'm sure that ASP.NET MVC will be great for those who think that ASP.NET MVC
is great. I just hope we don't get another case of the "Web Site" problem,
where Microsoft decided that we all should be creating Web Sites instead of
Web Application Projects.
 
A

Author

Gregory said:
It is very Rails like. It is designed to completely separate UI from
business rules and data access. This works if you just consider the actual
painting of the form UI. If you consider the entire wb application to be UI,
then most of the examples are still doing horrible on separation of
concerns, although the code is not in the actual UI element (whether ASPX or
otherwise).

I am not sure whether MVC will take off. I suspect not until the tools catch
up with the ASP.NET team. After that, I think it will take off, but only
time will tell.

As for the why? ASP.NET needed its rails. ;-)

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************

It looks like mvc will be included in future releases of the .net
framework. since scott guthrie has a few blogs about it, I'd assume
that his team is seriously working on it.

OK, MVC may be a good idea, but can we avoid embedding our codes in
the markup with <% and %>? Are we gonna have a struts for asp.net
mvc?
 
A

Author

Gregory said:
It is very Rails like. It is designed to completely separate UI from
business rules and data access. This works if you just consider the actual
painting of the form UI. If you consider the entire wb application to be UI,
then most of the examples are still doing horrible on separation of
concerns, although the code is not in the actual UI element (whether ASPX or
otherwise).

I am not sure whether MVC will take off. I suspect not until the tools catch
up with the ASP.NET team. After that, I think it will take off, but only
time will tell.

As for the why? ASP.NET needed its rails. ;-)

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************

It looks like mvc will be included in future releases of the .net
framework. since scott guthrie has a few blogs about it, I'd assume
that his team is seriously working on it.

OK, MVC may be a good idea, but can we avoid embedding our codes in
the markup with <% and %>? Are we gonna have a struts for asp.net
mvc?
 
B

bruce barker

the mvc pattern is very old, and pretty tried and true and its great
that microsoft has finally discovered it after all these years.

if you do not see the benefits of the mvc pattern then by all means
stick with webforms. they are bound to be the most common coding practice.

the controller is not the business layer. its the conduit to the
business layer. it supplies actions to the business layer, but should
not be part of it.

another approach is to combine mvc with a dynamic language and get the
ruby on rails productivity for a database driven site.

-- bruce (sqlwork.com)
 
B

bruce barker

there are couple disadvantages with mvc

1) no UI designer tools for it at this point.
2) requires good understanding of anonymous function and lambda
expressions to take full use of it.
3) coding is harder with a highly typed languages like c# and vb.net,
but dynamic style features are being added to these languages.
4) requires you know the mvc pattern and has a littler longer learning
curve.
5) doesn't attempt to hide the stateless nature of a web site from the
coder.


why <% %>?

its because of the limitations of the asp.net control syntax. all it
allows are name value pairs (properties) which are strongly typed. in
mvc generally you want messages for the parameter value, and asp.net
control syntax will not cut it.

you could easily write some asp.net server controls that called the html
helper function at render, but you'd end up restricting the binding
syntax, so that you had to use codebehind code, and you really don't
want codebehind code in a view.

-- bruce (sqlwork.com)
 
B

bruce barker

they are copying ruby on rails which is template based (Rhtml) more than
struts. the current view engine is the webforms page and its syntax,
which matches ruby on rails pretty close.

there are alternate view engines available, Haml for one, and while a
more struts like one could be added, the current trend with mvc web
viewers is template based.



-- bruce (sqlwork.com)
 
A

Author

they are copying ruby on rails which is template based (Rhtml) more than
struts. the current view engine is the webforms page and its syntax,
which matches ruby on rails pretty close.

there are alternate view engines available, Haml for one, and while a
more struts like one could be added, the current trend with mvc web
viewers is template based.

-- bruce (sqlwork.com)

Is it the case that ASP.NET MVC will not be event driven, but instead
will be controller driven? For example, in a regular web form, we can
use the server side button control like <asp:Button ID="btnLogin"
runat="Server" OnClick="btnLogin_Click"> and implement the click event
handler.

But in ASP.MVC, I see this becomes

<form method="post" action="/Home/Login">
[snip]
<input type="submit" value="Log In" />
</form>

No mas event handler.
 
G

Gregory A. Beamer \(Cowboy\) - MVP

Author said:
It looks like mvc will be included in future releases of the .net
framework. since scott guthrie has a few blogs about it, I'd assume
that his team is seriously working on it.

I understand it is in .NET 4.0, but I cannot confirm it, although I suspect
there will be a 2010 build for PDC that might have bits in it.
OK, MVC may be a good idea, but can we avoid embedding our codes in
the markup with <% and %>? Are we gonna have a struts for asp.net
mvc?

First, do not get overly consumed on the samples out there. Most of them
suck. In addition, they use the ASPX implementation for views. If you don't
like the ASPX implementation, you can use other methods to set up your
views. People have built adapters for a variety of other view (UI)
methodologies for ASP.NET MVC. A search should find one or more rather
quickly. Not sure if any out there now are struts like, however.

I am not that worried about <% %> as they are just tokens. You are not
really running code in the page, you are setting up regions that your
controller parses and uses to set up UI. It looks a lot like ASP, which
bothers some people. Once you start working with it, it is not that bad,
although a controller with a lot of code still tightly couples code and UI,
which is bad.

I forget which of the MS employees (Haack, Hanselman, Guthrie, etc.) posted
a sample with a different method of setting up views, but there are samples
out there. once again, not sure about struts, but I am sure someone will do
one, if there is a market for it.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
 
G

Gregory A. Beamer \(Cowboy\) - MVP

Many of the ASP.NET controls can be dropped on a page and have the proper
postback(s) created. I imagine you will see more as MVC matures. But if you
opt for this direction, you will be stuck with <% %> for anything outside of
the control "box".

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
they are copying ruby on rails which is template based (Rhtml) more than
struts. the current view engine is the webforms page and its syntax,
which matches ruby on rails pretty close.

there are alternate view engines available, Haml for one, and while a
more struts like one could be added, the current trend with mvc web
viewers is template based.

-- bruce (sqlwork.com)

Is it the case that ASP.NET MVC will not be event driven, but instead
will be controller driven? For example, in a regular web form, we can
use the server side button control like <asp:Button ID="btnLogin"
runat="Server" OnClick="btnLogin_Click"> and implement the click event
handler.

But in ASP.MVC, I see this becomes

<form method="post" action="/Home/Login">
[snip]
<input type="submit" value="Log In" />
</form>

No mas event handler.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top