I have been trying to find the different between MVC and 3-tier architecture in ASP.NET. I referred to some previous some previous questions and some pages, but could find a clear answer.
Here is a a msdn page about MVC implementation: http://msdn.microsoft.com/en-us/library/ff647462.aspx
Consider, I ahve this code:
Single page aspx UI and code as well
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head>
<title>start</title>
<script language="c#" runat="server">
void Page_Load(object sender, System.EventArgs e)
{
String selectCmd = "select * from Recording";
SqlConnection myConnection =
new SqlConnection(
"server=(local);database=recordings;Trusted_Connection=yes");
SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd,
myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "Recording");
recordingSelect.DataSource = ds;
recordingSelect.DataTextField = "title";
recordingSelect.DataValueField = "id";
recordingSelect.DataBind();
}
</script>
</head>
<body>
<asp:dropdownlist id="recordingSelect" runat="server" />
<asp:button runat="server" text="Submit" OnClick="SubmitBtn_Click" />
</form>
</body>
</html>
Now, consider I have different files for
---- View and Code-behind spearated ----
.aspx
<%@ Page language="c#" Codebehind="Solution.aspx.cs"
AutoEventWireup="false" Inherits="Solution" %>
<html>
<asp:dropdownlist id="recordingSelect" runat="server" />
</form>
</body>
</html>
.aspx.cs
using System;
using System.Data;
using System.Data.SqlClient;
public class Solution : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
String selectCmd = "select * from Recording";
SqlConnection myConnection =
new SqlConnection(
"server=(local);database=recordings;Trusted_Connection=yes");
SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd, myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "Recording");
recordingSelect.DataSource = ds;
recordingSelect.DataTextField = "title";
recordingSelect.DataValueField = "id";
recordingSelect.DataBind();
}
}
- Seeing the above msdn page link for the
Controller
class, I am not able to discern the difference between the business logic (that would have been similar for a middle tier in a 3 tier architecture) and the controller. - Is 3-tier and MVC completely different thing? Are the ASP.NET application in Visual Studio already separated file as in MVC form? If these are not different, which one is the preferred style?
- What's the MVC framework about then if the .aspx and .aspx.cs are already spearated?