0% found this document useful (0 votes)
1 views8 pages

MVC,JS

The document provides an overview of MVC architecture, including its components: Models, Views, and Controllers, as well as the MVC lifecycle. It covers various jQuery methods such as map(), grep(), and filter(), along with AJAX for asynchronous data loading, and discusses HTML helpers in MVC for rendering HTML controls. Additionally, it touches on session management, routing, error handling, and LINQ for data querying in .NET applications.

Uploaded by

guruguru2810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views8 pages

MVC,JS

The document provides an overview of MVC architecture, including its components: Models, Views, and Controllers, as well as the MVC lifecycle. It covers various jQuery methods such as map(), grep(), and filter(), along with AJAX for asynchronous data loading, and discusses HTML helpers in MVC for rendering HTML controls. Additionally, it touches on session management, routing, error handling, and LINQ for data querying in .NET applications.

Uploaded by

guruguru2810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

Mvc architecture :

Models - Represents the data.


View - display the data into the user.
Controller - handle the request and send response to the appropriate view.

Mvc life cycle:


Two steps here first of understanding the type of request and return the responses
to appropriate view .
Second step
Map:
This�map()�Method in jQuery is used to translate all items in an array or object to
new array of items.

grep():
This grep() method in jQuery is used to finds the elements of an array that
satisfies a filter function.not affected in original array.
Syntax:
jQuery.grep(array, function(element, index) [, invert])
array:�This parameter holds the array like object for searching.
function(element, index):�It is the filter function which takes two
arguments,�element�which holds the element of the array and�index�which holds the
index of that particular element.
invert:�It is false or not passed, then the function returns an array having all
elements for which �callback� returns true. If this is passed true, then the
function returns an array having all elements for which �callback� returns false.
Filter:
The filter()�method is used to filter out all the elements that do not match the
selected criteria and those matches will be returned.
Syntax:
$(selector).filter(criteria, function(index))

Ajax:
Used to load the data from server side without browser page refresh.
Ajax Syntax:

async:--Set to false if the request should be sent synchronously. Defaults to true.


type:-- HTTP Request and accepts a valid HTTP verb.
url:--URL for the request.
data:--The data to be sent to the server. This can either be an object or a query
string.
contentType:--content type of the request you are making. The default is
'application/x-www-form-urlencoded'.
datatype:By default, jQuery will look at the MIME type of the response if no
dataType is specified.Accepted values are text, xml, json, script, html jsonp.
success:--The function receives the response data (converted to a JavaScript object
if the DataType was JSON),
as well as the text status of the request and the raw request object.
error:--A callback function to run if the request results in an error. The function
receives the raw request object and the text status of the request.

$.ajax({
type: "POST",
url: "/Home/JqAJAX",
data: JSON.stringify(Student),
dataType: "json"
contentType: 'application/json; charset=utf-8',
success: function(data) {
alert(data.msg);
},
error: function() {
alert("Error occured!!")
}
});

MasterLayout page:
its Located at Shared folder in MVC APPlication
you learn how to create a common page layout for multiple pages in your application
by taking advantage of view master pages
You also can take advantage of view master pages to share common content across
multiple pages in your application.
For example, you can place your website logo, navigation links, and banner
advertisements in a view master page.
That way, every page in your application would display this content automatically

Ajax Method :Asynchronous Javascript And XML


--ajax() method is used to perform an AJAX (asynchronous HTTP) request.
$.ajax() Performs an async AJAX request.
$.get() Loads data from a server using an AJAX HTTP GET request.
$.post() Loads data from a server using an AJAX HTTP POST request

$.ajax () Method Configuration option:


async:its default true , set to the false request Synchronusly.
type: here we have used in the form of http verbs --> GET,POST
url:Url for the Request -->(Controller , Action method ) or Directly used to URL
data:Data can be sent to the server its Object or Query String .
datatype:--text, xml, json, script, html jsonp.
contenttype:content type of the request you are making--by default (application/x-
www-form-urlencoded)
success:
error:
<script type="text/javascript">
$(document).ready(function() {
$(function() {
$('#btnSubmit').click(function(event) {
event.preventDefault();
var Student = {
ID: '10001',
Name: 'Shashangka',
Age: 31
};
$.ajax({
type: "POST",
url: "/Home/JqAJAX",
data: JSON.stringify(Student),
dataType: "json"
contentType: 'application/json; charset=utf-8',
success: function(data) {
alert(data.msg);
},
error: function() {
alert("Error occured!!")
}
});
});
});
});
</script>
Grep:
--------
jQuery.grep( array, function [, invert ])
----------------------------------------------
Def:
grep() method in jQuery is used to finds the elements of an array that satisfies a
filter function.
Array:
--Type:ArrayLikeObject
--Searchigh the Object
function :
Function (Object elementOfArray,integer Indexof Array)=>Boolean
--Here the first argument of the fuction in sitem ,second one index of the item .
invert:
--Invert is false--array consisting all elements for which call return is true.
--Invert is true--array consisting all elements for which call return is false.

jQuery.map(array,callback)
jQuery.map(object,callback)
Def:
map() Method in jQuery is used to translate all items in an array or object to new
array of items.

--array:Array to translate
--object:object to translate
--Callback:
callback(Object elementOfArray,integer Indexof Array)=>Boolean
callback: This parameter holds the function to process each item against.

// The following object masquerades as an array.


var fakeArray = { "length": 2, 0: "Addy", 1: "Subtracty" };

// Therefore, convert it to a real array


var realArray = $.makeArray( fakeArray )

// Now it can be used reliably with $.map()


$.map( realArray, function( val, i ) {
// Do something
});

jQuery Array.Map
Note: map() does not execute the function for array elements without values.
Note: this method does not change the original array.

Filter:$(selector).filter(criteria, function(index))
Def:
filter() method is used to filter out all the elements that do not match the
selected criteria and those matches will be returned.
<html>

<head>
<title>GEEKS FOR GEEKS ARTICLE</title>
<script src="https://ajax.googleapis.com/ajax/libs/
jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("li").filter(".first, .last").css("color", "red")
.css("backgroundColor", "yellow");
});
</script>
</head>

<body>
<ul>
<li class="first">GeeksForGeeks</li>
<li class="first">GeeksForGeeks</li>
<li class="middle">GeeksForGeeks</li>
<li class="last">GeeksForGeeks</li>
<li class="last">GeeksForGeeks</li>
</ul>
</body>

</html>

HTML Helpres :
--Just Like a Web Forms control in ASP.Net,HTML Helpers used to modify HTML
Page ,it is morlight weight
In Most of the method HTML helpers return as string, In MVC you can create own HTML
Helpers or Use Built in HTML helpers

Standard HTML Helper:


Purpose:used to render the most common type of HTML controls like Label,TextBox,
Password,
TextArea, CheckBox, RadioButtion, DropDownList, Listbox,Display,Editor and
ActionLink
@Html.ActionLink() - Used to create link on html page
@Html.TextBox() - Used to create text box
@Html.CheckBox() - Used to create check box
@Html.RadioButton() - Used to create Radio Button
@Html.BeginFrom() - Used to start a form
@Html.EndFrom() - Used to end a form
@Html.DropDownList() - Used to create drop down list
@Html.Hidden() - Used to create hidden fields
@Html.label() - Used for creating HTML label is on the browser
@Html.TextArea() - The TextArea Method renders textarea element on browser
@Html.Password() - This method is responsible for creating password input field on
browser
@Html.ListBox() - The ListBox helper method creates html ListBox with scrollbar on
browser

Strongly Typed HTML Helpers:


Purpouse:
All strongly-typed HTML helpers depend on the model class. We can create this
using a lambda expression of extension method of HTML helper class
@Html.HiddenFor()
@Html.LabelFor()
@Html.TextBoxFor()
@Html.RadioButtonFor()
@Html.DropDownListFor()
@Html.CheckBoxFor()
@Html.TextAreaFor()
@Html.PasswordFor()
@Html.ListBoxFor()

List of Templated HTML Helpers


Purpouse:
When we use an HTML helper method, such as LabelFor() or TextBoxFor(), then it
displays the model property in a fixed manner. .
.. Similarly, the TextBoxFor() HTML Helper method renders a textbox in which
the model property value is shown for editing
@Html.Display()
@Html.DisplayFor()
@Html.DisplayName()
@Html.DisplayNameFor()
@Html.DisplayText()
@Html.DisplayTextFor()
@Html.DisplayModelFor()
Edit / Input:
@Html.Editor()
@Html.EditorFor()
@Html.EditorForModel()

Ouput Cache:
We need caching in many different scenarios to improve the performance of an
application
Purpouse:
you can take advantage of the output cache to avoid executing a database query
every time a user invokes the same controller action.
In this case, the view will be retrieved from the cache instead of being
regenerated from the controller action.
Caching enables you to avoid performing redundant work on the server

[OutputCache(Duration = 60)]
public ActionResult Index(){
var employees = from e in db.Employees
orderby e.ID
select e;
return View(employees);
}

Bundling :
Bundling is a new feature in ASP.NET 4.5 that makes it easy to combine or bundle
multiple files into a single file.
You can create CSS, JavaScript and other bundles. Fewer files means fewer HTTP
requests and that can improve first page load performance
Bundling and Minification provide us a way to both reduce the number of requests
needed to get JS and CSS resource files and reduce the size of the files
themselves,
thereby improving the responsiveness of our apps.
Purpouse:
They are nice little optimizations for our MVC apps that can improve performance
and add responsiveness.

we call WCF service from Javascript?


It's very easy, you have to pass url with method, parameter (value from textbox)
specify data type and callback function. Now you can run webapplication,
put some text in input box and press button �jQuery call� Calling WCF service with
Microsoft Ajax is much more easy.
View state:
View state is the page-level state management technique used in the ASP.NET page
framework to retain the value of controls and page between round trips.
Data objects such as hash tables, strings, array objects, array list objects,
Boolean values and custom-type converters can be stored in view state.
ViewModel:
ViewModel is a class that contains the fields which are represented in the
strongly-typed view. It is used to pass data from controller to strongly-typed view
View state is ideally used when the data to be preserved is relatively small and
the data need not be secured.
session state:
In ASP.NET session is a state that is used to store and retrieve values of a user.
It helps to identify requests from the same browser during a time period (session).
It is used to store value for the particular time session. By default, ASP.NET
session state is enabled for all ASP.NET applications.
Purpouse: Avoiding DB hits, For Ex: Availablity Modify Search with same details ,
that time we have fetched availablity from Session with help of Session ID
Cookies :
Cookies are one of the State Management techniques, so that we can store
information for later use.
Cookies are small files that are created in the web browser's memory (if they're
temporary) or on the client's hard drive (if they're permanent)

Types Of Action FIlters:


void OnActionExecuted(ActionExecutedContext filterContext)-- It is called just
after the action method is called.
void OnActionExecuting(ActionExecutingContext filterContext)--It is called just
before the result is executed; it means before rendering the view.

void OnResultExecuted(ResultExecutedContext filterContext)--It is called just after


the result is executed, it means after rendering the view.
void OnResultExecuting(ResultExecutingContext filterContext)--Called before the
action result that is returned by an action method is executed.

Purpouse: OnResultExecuted and OnResultExecuting


which can be used to execute custom logic before or after the result executes.

session :
MVC the controller decides how to render view, meaning which values are accepted
from View and which needs to be sent back in response.
ASP.NET MVC Session state enables you to store and retrieve values for a user when
the user navigatesto other view in an ASP.NET MVC application.

Purpouse:
MVC provides three ways (TempData, ViewData and ViewBag) to manage session, apart
from that we can use session variable, hidden fields and HTML controls for the
same.
But like session variable these elements cannot preserve values for all requests;
value persistence varies depending the flow of request.
session Storage Format:
Session stores the data in key and value format. Value gets stored in object
format, so any type of data (string, integer, class collection etc.)

Session-State modes are 5 type:


InProc mode:
which stores session state in memory on the Web server. This is the default.
StateServer mode:
which stores session state in a separate process called the ASP.NET state service.
This ensures that session state is preserved if the Web application is restarted
and also makes session state available to multiple Web servers in a Web farm.
SQLServer mode:
SQLServer modestores session state in a SQL Server database.
This ensures that session state is preserved if the Web application is restarted
and also makes session state available to multiple Web servers in a Web farm.
Custom mode: which enables you to specify a custom storage provider.
Off mode: which disables session state.
Action filters are generally used to apply cross-cutting concerns such as logging,
caching, authorization, etc
Scaffolding:
Scaffolding is a technique used by many MVC frameworks like ASP.NET MVC, Ruby on
Rails, Cake PHP and Node. JS etc.
to generate code for basic CRUD (create, read, update, and delete) operations
against your database effectively.
Further you can edit or customize this auto generated code according to your need

Routing :
Def:Routing is a mechanism in MVC that decides which action method of a controller
class to execute.
Without routing there's no way an action method can be mapped. to a request.
Routing is a part of the MVC architecture so ASP.NET MVC supports routing by defaul
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Student",
url: "students/{id}",
defaults: new { controller = "Student", action = "Index"}
);
Web API Routing:
Web API routing is similar to ASP.NET MVC Routing. It routes an incoming HTTP
request to a particular action method on a Web API controller.
Web API supports two types of routing: Convention-based Routing. Attribute Routing.
public static void Register(HttpConfiguration config)
{
// Enable attribute routing
config.MapHttpAttributeRoutes();

// Add default route using convention-based routing


config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
Error Handling Types in MVC :
Web.Config customErrors
MVC HandleErrorAttribute
Controller.OnException method
HttpApplication Application_Error event
Collect exceptions via .NET profiling with Retrace

Enabling a WCF Transaction


Step 1-Creation of two WCF Services. ...
Step 2- Method creation and its attribution with TransactionFlow attribute
Step 3-Implementation of WCF service with TransactionScopeRequired attribute.
Step 4-Enabling Transaction Flow by WCF Service Config File.

Transaction Properties of WCF


Atomic:
All the operations must act as a single indivisible operation at the completion of
a transaction
Consistency:
Whatever may be the operation set, the system is always in a state of consistency,
i.e., the outcome of the transaction is always as per the expectation.
Isolation :
The intermediary state of system is not visible to any entities of the outer world
till the transaction is completed.
Durablity:
Committed state is maintained regardless of any kind of failure (hardware, power
outage, etc.)

LINQ:
LINQ stands for Language Integrated Query.
LINQ is a data querying API that provides querying capabilities to .NET
languages with a syntax similar to a SQL.
LINQ queries use C# collections to return data.
LINQ in C# is used to work with data access from sources such as objects, data
sets, SQL Server, and XML.

1.Standardized way of querying multiple data sources : The same LINQ syntax
can be used to query multiple data sources.
2.Compile time safety of queries : It provides type checking of objects at
compile time.
3.Readable code : LINQ makes the code more readable so other developers can
easily understand and maintain it.
Types of LINQ:
LINQ to Objects.
LINQ to XML(XLINQ)
LINQ to DataSet.
LINQ to SQL (DLINQ)
LINQ to Entities.

Advantages of LINQ :
It offers Syntax Highlighting to find out errors during Design time.
Write queries easily
Development time is reduced.
Easy debugging
Transformation of data from one to another easily like SQL to XML

Undefined and null in javascript :


In JavaScript, undefined is a type, whereas null an object.
It means a variable declared, but no value has been assigned a value.
Whereas, null in JavaScript is an assignment value.

You might also like