Advertisements

Archive

Posts Tagged ‘ASP.NET MVC Framework’

Razor vs WebForm(aspx)


RAZOR Web Form(ASPX)
Razor View Engine is an advanced view engine and introduced with MVC3. This is not a language but it is a mark-up syntax. ASPX View Engine is the default view engine for the ASP.NET MVC that is included with ASP.NET MVC from the beginning.
Namespace:System.Web.Razor. Namespace: System.Web.Mvc.WebFormViewEngine
Extension:.cshtml with C# or

.vbhtml with VB extension for views, partial views, editor templates and for layout pages.

Extension:.aspx extension for views

.ascx extension for partial views & editor templates and .master extension for layout/master pages.

RAZOR is much easier and cleaner than Web Form. It uses @ symbol in coding.
e.g.@Html.ActionLink(“link”, “click”)
ASPX Uses <% and %> delimiter in coding.
e.g. <%: Html.ActionLink(“link”, “Click”) %>
RAZOR engine comparatively slow but provides better security than ASPX. Razor Engine prevents XSS attacks(Cross-Site Scripting Attacks) means it encodes the script or html tags like <,> before rendering to view. Web Form is comparatively faster but less secure than RAZOR. Web Form Engine does not prevent XSS attacks means any script saved in the database will be fired while rendering the page
Razor Engine, doesn’t support design mode in visual studio means you cannot see your page look and feel without running application. Web Form engine support design mode in visual studio means you can see your page look and feel without running the application.
Razor Engine support TDD (Test Driven Development) since it is not depend on System.Web.UI.Page class. Web Form Engine doesn’t support TDD (Test Driven Development) since it depend on System.Web.UI.Page class which makes the testing complex.

 

Advertisements

MVC: From where to find System.Web.MVC dll in a system

April 6, 2015 3 comments

Default path for System.Web.MVC dll

MVC 2
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 2\Assemblies\System.Web.Mvc.dll

MVC 3
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll

MVC 4
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Web.Mvc.dll

MVC 5
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Stack 5\Packages\ Microsoft.AspNet.Mvc.5.0.0\lib\net45\System.Web.Mvc.dll

Hope this help !

REST Services


REST : Representational State Transfer

Principle of REST Services

  1. Everything is resource
  2. Every resource identified by unique URI
  3. User simple and uniform interface (like GET, POST, PUT, DELETE)
  4. All communication done via Representation
  5. Be Stateless

Will add some information soon !

Thanks

How to create a Pie chart using ASP.Net and C#

December 23, 2013 Leave a comment

43

 

There are 4 things you need to do in order to get this configured and working on your machine, remember, however that you will need Visual Studio 2010 and .Net 4.
  • Create a Website project
  • Modify the Web.Config file
  • Modify the Default.aspx file
  • Modify the Default.aspx.cs file
I’ll assume you know how to create a Website project…File, New, Website, ASP.Net project…
The Web.Config file needs to be modified to contain the httpHandler and controls. These configurations enable the asp:Chart tag which is used in the Default.aspx file.

<httpHandlers>

  <add path="ChartImg.axd"
      verb="GET,HEAD,POST"
      type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler,System.Web.DataVisualization,
      Version=4.0.0.0, Culture=neutral,
      PublicKeyToken=31bf3856ad364e35"
      validate="false"/>
</httpHandlers>
<controls>
  <add tagPrefix="asp"
      namespace="System.Web.UI.DataVisualization.Charting"
      assembly="System.Web.DataVisualization,
      Version=4.0.0.0,
      Culture=neutral,
      PublicKeyToken=31bf3856ad364e35"/>
</controls>
In the Default.aspx file we will add the chart, titles, legend, series and chartareas.

<asp:chart id="Chart1" runat="server" Height="300px" Width="400px">

  <titles>
    <asp:Title ShadowOffset="3" Name="Title1" />
  </titles>
  <legends>
    <asp:Legend Alignment="Center" Docking="Bottom" IsTextAutoFit="False"
    Name="Default" LegendStyle="Row" />
  </legends>
  
  <series>
    <asp:Series Name="Default" />
  </series>
  <chartareas>
    <asp:ChartArea Name="ChartArea1" BorderWidth="0" />
  </chartareas>
</asp:chart> 
And lastly, we will add the code to the code-behind file to populate and configure the chart. First thing I do is to load the data values for the chart. If this was implemented in a program being used to represent real data, then the values would not be hardcoded. You would connect to a database, run a query and then have your business logic create the contents of the values. For simplicity, I hard coded the values. Then I simply went through and set the properties that created the above Pie Chart.

protected void Page_Load(object sender, EventArgs e)

{
  double[] yValues = { 71.15, 23.19, 5.66 };
  string[] xValues = { "AAA", "BBB", "CCC" };
  Chart1.Series["Default"].Points.DataBindXY(xValues, yValues);
  Chart1.Series["Default"].Points[0].Color = Color.MediumSeaGreen;
  Chart1.Series["Default"].Points[1].Color = Color.PaleGreen;
  Chart1.Series["Default"].Points[2].Color = Color.LawnGreen;
  Chart1.Series["Default"].ChartType = SeriesChartType.Pie;
  Chart1.Series["Default"]["PieLabelStyle"] = "Disabled";
  Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
  Chart1.Legends[0].Enabled = true;
}
Hope this help !

Visual Studio warning: “Some of the properties associated with the solution could not be read”

December 4, 2013 Leave a comment

I just fixed a similar issue with a VS2010 solution with 42 projects… The cause was a duplicated

GlobalSection(TeamFoundationVersionControl)

section in the solution file. I closed the solution, removed the duplicate GlobalSection(TeamFoundationVersionControl) config and reloaded the solution and the warning message was gone.

Hope this help!

Understanding asp.net MVC (Model View Controller) architecture

November 28, 2012 4 comments

This article is intended to provide basic concept and fundamentals of asp.net MVC (Model View Controller) architecture workflow for beginners.

Introduction:

“M” “V” “C” stands for “MODEL” “VIEW” “CONTROLLER” , asp.net MVC is an architecture to develop asp.net web applications in a different manner than the traditional asp.net web development , web applications developed with asp.net MVC is even more SEO (Search Engine Friendly ) friendly.

Developing asp.net MVC application requires Microsoft .net framework 3.5 or higher.

MVC interaction with browser:

Like a normal web server interaction, MVC application also accept request and respond web browser same way.


Inside MVC architecture:

Whole asp.net MVC architecture is based on Microsoft .net framework 3.5 and in addition uses LINQ to SQL Server.

What is a Model?

  1. MVC model is basically a C# or VB.net class
  2. A model is accessible by both controller and view
  3. A model can be used to pass data from Controller to view.
  4. A view can use model to display data in page.

What is a View?

  1. View is an ASPX page without having a code behind file
  2. All page specific HTML generation and formatting can be done inside view
  3. One can use Inline code (server tags ) to develop dynamic pages
  4. A request to view (ASPX page) can be made only from a controller’s action method

What is a Controller?

  1. Controller is basically a C# or VB.net class which inherits system.mvc.controller
  2. Controller is a heart of whole MVC architecture
  3. Inside Controller’s class action methods can be implemented which is responsible for responding to browser OR calling view’s.
  4. Controller can access and use model class to pass data to view’s
  5. Controller uses ViewData to pass any data to view


MVC file structure & file naming standards

MVC uses a standard directory structure and file naming standards which is very important part of MVC application development.

Inside the ROOT directory of the application there must be 3 directories each for model, view and Controller.

Apart from 3 directories there must have a Global.asax file in root folder. And a web.config like a traditional asp.net application.

  • Root [directory]
    •  Controller [directory]
      • Controller CS files
    •  Models [directory]
      • Model CS files
    •  Views [directory]
      • View CS files
    • Global.asax
    • Web.config

Asp.net MVC Execution life cycle

Here is how MVC architecture executes the requests to browser and objects interactions with each other.

A step by step process is explained below: [Refer figure as given below]


Step 1: Browser request

Browser request happens with a specific URL. Let’s assume that user entering URL like: [xyz.com]/home/index/

Step 2: Job of Global.asax – MVC routing

The specified URL will first get parsed via application_start() method inside Global.asax file. From the requested URL it will parse the Controller, Action and ID.

So for [xyz.com]/home/index/:

Controller = home

Action = index()

ID = empty — we have not specified ID in [xyz.com]/home/index/, so it will consider as empty string

Step 3: Controller and Action methods

MVC now find the home controller class in controller directory. A controller class contains different action methods,

There can be more than one action method, but MVC will only invokes the action method which is been parsed from the URL, its index() in our case.

So something like: homeController.index() will happen inside MVC controller class.

Invoking action method can return plain text string OR rendered HTML by using view.

Step 4: Call to View (ASPX page)

Invoking view will return view() . a call to view will access the particular ASPX page inside the view directory and generate the rendered HTML from the ASPX and will respond back to the browser.

In our case controller was home and action was index(). So calling view() will return a rendered HTML from the ASPX page located at /views/home/index.aspx.

This is it, the whole process ends here. So this is how MVC architecture works.