Showing posts with label MVC. Show all posts
Showing posts with label MVC. Show all posts

Difference Between MVC Razor View Engine and ASPX View Engine


Razor View Engine and ASPX View Engine



        Razor View Engine          ASPX View Engine
1
The namespace for Razor Engine is System.Web.Razor.
The namespace for Webform Engine is System.Web.Mvc.WebFormViewEngine.
2
Razor Engine is an Advanced View Engine that was introduced with MVC3.This is a New Markup Syntax.
Web Form Engine is the Default View Engine for the Asp.net MVC that is included with Asp.net.
3
Razor Engine is  slower than Webform Engine.
Webform Engine is  Faster than  Razor Engine.
4
Razor syntax are easy to learn and clean than Web Form syntax. Razor uses @ symbol.

@Html.ActionLink("", "")
Webform uses <% and %> delimiters

<%: Html.ActionLink("", "") %>
5
I.Razor Engine, doesn't support design mode in Visual Studio .

II.Razor Engine prevents XSS attacks (Cross - Site Scripting Attack).

III.Razor Engine support  Test Driven Development (TDD).
I.Web Form engine support design mode in Visual Studio.

II.Web Form Engine does not prevent XSS attacks (Cross - Site Scripting Attack).

III.Web Form Engine doesn't support Test Driven Development (TDD).






Difference Between Asp.Net Webforms and ASP.NET MVC



Difference Between Asp.Net Webforms And ASP.NET MVC



        ASP.NET WebForms      ASP.NET MVC         
1
Maintains the MasterPage.
Maintains the Layouts.
MVC is a Model View Controller.
2
Code Reusablity for User Controls.
Code Reusablity for Partial Views.
3
Page Controller Patterns.
Every Page has a Code-Behind Class that acts as a Controller.
Front Controller Patterns.
This is a Single Central controller for all Pages.
4
ASP.NET WebForms is not a OpenSource.
ASP.NET MVC ia a OpenSource.
5
I.ASP.NET WebForms uses Web Forms Syntax.

II.Controls Used Server Controls.
I.ASP.NET MVC uses Cutsomized Syntax.
Razor View Engine(Default).
II.Controls Used HTML Helpers.





What Is MVC Step By Step Video

MVC


MVC

Model:

Models represent data and thus knowledge. It could be a single object or a hierarchy/tree of objects. However, they should only be dealing with only one problem domain, for example data about appointments is not in the same problem domain as the color of rectangle used to represent the appointment on the screen.

View: 

Views are the visual representation of their respective Models. It can highlight certain Model attributes (properties) and suppress others.
A presentation of data in a particular format, triggered by a controller's decision to present the data. They are script based templating systems like JSP, ASP, PHP and very easy to integrate with AJAX technology.

Controllers: 

The unit of interaction that serves as a link between the User and the System. It presents data to User by arranging various Views appropriately. It also provides means for user input such as mouse operations and keystrokes. A controller should never supplement a View.
The controller is responsible for responding to user input and perform interactions on the data model objects. The controller receives the input, it validates the input and then performs the business operation that modifies the state of the data model.

What is MVC  Step by Step  Video 






ASP.NET MVC Pipeline


1.Controller Factories
2.Action Invokers
3.Model Binders
4.Action Filters
5.Action Results
6.View Engines













How to Insert Data in MVC Razor View Engine in Asp.Net

                             MVC  INSERT




DEMO

Create - table Name (register)

CREATE TABLE [dbo].[register] (
    [userid]   INT          IDENTITY (1, 1) NOT NULL,
    [username] VARCHAR (50) NOT NULL,
    [password] VARCHAR (50) NOT NULL,
    [name]     VARCHAR (50) NOT NULL,
    [mobile]   VARCHAR (50) NOT NULL,
    [email]    VARCHAR (50) NOT NULL,
    PRIMARY KEY CLUSTERED ([userid] ASC)


);


Coding for Validation


 using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
   
    public partial class register
    {
        public int userid { getset; }

        [Required(ErrorMessage = "Please Enter UserName", AllowEmptyStrings = false)]

        public string username { getset; }

        [Required(ErrorMessage = "Please Enter Valid Password", AllowEmptyStrings = false)]
        [DataType(System.ComponentModel.DataAnnotations.DataType.Password)]
        [StringLength(50, MinimumLength = 15, ErrorMessage = "please Password Lenth 15 Long")]

        public string password { getset; }


        [Required(ErrorMessage = "Please  Enter Full name", AllowEmptyStrings = false)]

        public string name { getset; }
        [Required]
    
        public string mobile { getset; }

        [Required]

        [RegularExpression("^([0-9a-zA-Z]([-\\.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$", ErrorMessage = "Invalid Email ID")]

        public string email { getset; }
    }
}


Coding for Insert


  public ActionResult Register()
        {
            return View();
        }
       
        [HttpPost]
     
  [ValidateAntiForgeryToken]      

        public ActionResult register(register r)

        {
            if (ModelState.IsValid)
            {
                using (Database1Entities de = new Database1Entities())
                {
                    de.registers.Add(r);

                    de.SaveChanges();

                    ModelState.Clear();

                    r = null;

         ViewBag.Message = "Data Registered Successfully";              
                               
                }
             
            }

            return View(r);
      
        }


CSHTML Coding


@model MVC__REGISTRATION.register

@{
    ViewBag.Title = "register";
}

<h2>register</h2>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>register</legend>

         @Html.AntiForgeryToken()


        <div class="editor-label">
            @Html.LabelFor(model => model.userid)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.userid)
            @Html.ValidationMessageFor(model => model.userid)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.username)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.username)
            @Html.ValidationMessageFor(model => model.username)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.password)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.password)
            @Html.ValidationMessageFor(model => model.password)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.name)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.name)
            @Html.ValidationMessageFor(model => model.name)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.mobile)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.mobile)
            @Html.ValidationMessageFor(model => model.mobile)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.email)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.email)
            @Html.ValidationMessageFor(model => model.email)
        </div>

        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")

}




Learn About ASP.NET MVC

ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that enables a clean separation of concerns and that gives you full control over markup for enjoyable, agile development. 


ASP.NET is a development framework for building web pages and web sites with HTML, CSS, JavaScript and server scripting.

ASP.NET supports three different development models:
Web Pages, MVC (Model View Controller), and Web Forms.



Web Applications with 3 logic layers:

The business layer (Model logic)
The display layer (View logic)
The input control (Controller logic)


MVC




First  Select - New Project 







Next  - Select  FrameWork  4 or 4.5  -  Select  Asp.Net MVC  Web  Application  3 or 4 -  Enter the Project  Name -  Click OK Button 








Next  - Open Window  Form - Select -  Internet Application

Next  - Select - Razor View Engine







 
Next  - Open the HomeController.cs Below like that










Next  - Right Click App-Data - Add- New Item 










Add -  SQL Server Database -  Add










Added The Database To App-Data Folder








Next  - Add the New Table Name - Select Tables - Right Click - Add New Table 









Create table Name (register)





After  Filling  Column name  - Select  Update Button Click 








Next - Select - Update Database Click 









Add - The register Table & Column Fields









Next - Select  - Solution Explorer - Right Click - Project Name(MVC REGISTRATION) -  Add - New Item









   Add the ADO.NET Entity Model -  Enter model - Name- OK      Button Click








Next -  Show Window -  Select - Generate from Database - Click Next Button 







Open New Window - Select - Your Databsae Name -  Database1Entities - Click  Next Button









Next  - Select  Your  Table Name(register)









Next - Create  Model.edmx  diagram1  (register table & Column Fields)









Next  - Create   model  for register table - Next Double click - register.cs - open  register table fields  &  Datatypes 








Next -Add - the  using System.ComponentModel.DataAnnotations;   for  Validation










Next -   Add the Validation for  All   register table Column fields  below like that









Next - Select  Controller - right click - Add - Controller 







Open window -  Controller Name - Default1Controller  - Template - Empty MVC Controller  - Add  Button click








Next - Added Default1Controllers -  Select  Default1Controller 







Next - Add 

[HttpPost]
        [ValidateAntiForgeryToken]





Next - Write the  Insert  Coding 
















Next  - Select  Build  - Right click - Select Build Solution  - Build the  Controller 










Next  - Right Click  -  Coding Page - Public Actionresult  Register() -  Add View  Click










Open - New Window -   Select - View(Register)-View Engine(Razor(CSHTML))- Select Strongly typed View - Model Class(register(MVC_Registration)) -Scaffold Tempalte(Empty) - Add Button Click 









Default1 View Name Generate

Next  - Automatically Generate -register.CSHTML Coding for Register  Column field Design 


Next  - Add @ Html.AntiForgerytoken()




                                           
              
                             
                                     Default1  View Name 










Next - run the program - Clcik   - F5 Buttton  - Go to Browser 








Next -  Add - the  View Name /  Controller Name(Default1/register)

Next - open  the Generated  Design  Page 










Next -  Without Fill Values  Validation Error Message  Show popup









All - Validation  Error Message Popup Shown  below 











Next - Password Strength  15 Given   Validation  Popup Show 









Next - Enter  - All Values -  Properly - Click Create Button 
      
      Registered Successfully  









Next - Enter  - Second  Values -  Properly - Click Create Button 

Registered Successfully









Next  - Open Table  - Select  Register  table  Right Click - Show table data -  Display the  Registered Data's