1.
Transport Security : Transport level security happens at the channel level.
Transport level security is the easiest to implement as it happens at the
communication level. WCF uses transport protocols like TCP, HTTP, MSMQ etc and
every of these protocols have their own security mechanisms. One of the common
implementation of transport level security is HTTPS. HTTPS is implemented over
HTTP protocols with SSL providing the security mechanism. No coding change is
required it's more of using the existing security mechanism provided by the
protocol.
2. Message Security : Message level security is implemented with message data itself. Due to this it is independent of the protocol. Some of the common ways of implementing message level security is by encrypting data using some standard encryption algorithm.
2. Message Security : Message level security is implemented with message data itself. Due to this it is independent of the protocol. Some of the common ways of implementing message level security is by encrypting data using some standard encryption algorithm.
With
the Factory pattern, you produce implementations (Apple, Banana, Cherry, etc.)
of a particular interface -- say, IFruit.
With the Abstract Factory pattern, you produce implementations of a particular Factory interface -- e.g., IFruitFactory. Each of those knows how to create different kinds of fruit.
With the Abstract Factory pattern, you produce implementations of a particular Factory interface -- e.g., IFruitFactory. Each of those knows how to create different kinds of fruit.
#
Factory
design Pattern:-
In this pattern we define an interface which will expose a method which will create objects for us. Return type of that method is never be a concrete type rather it will be some interface (or may be an abstract class)
Abstract Factory Design Pattern:-
In Abstract Factory we define an interface which will create families of related or dependent objects. In simple words, interface will expose multiple methods each of which will create some object. Again, here method return types will be generic interfaces. All this objects will together become the part of some important functionality.
• First of all both of them falls under Creational category and it means it will solves the problem pertaining to object creation.
• Factory Method and abstract factory pattern all are about creating objects.
In this pattern we define an interface which will expose a method which will create objects for us. Return type of that method is never be a concrete type rather it will be some interface (or may be an abstract class)
Abstract Factory Design Pattern:-
In Abstract Factory we define an interface which will create families of related or dependent objects. In simple words, interface will expose multiple methods each of which will create some object. Again, here method return types will be generic interfaces. All this objects will together become the part of some important functionality.
• First of all both of them falls under Creational category and it means it will solves the problem pertaining to object creation.
• Factory Method and abstract factory pattern all are about creating objects.
#
factory
design pattern give interface for creating object let the subclasses decide
which one to be instantiate.....(Virtual Constructor)
however abstract factory design pattern is a type of super factory that create of other factories...
both of them comes under creational design pattern
however abstract factory design pattern is a type of super factory that create of other factories...
both of them comes under creational design pattern
Extension
methods are a new feature in C# 3.0. An extension method enables us to add
methods to existing types without creating a new derived type, recompiling, or
modify the original types. We can say that it extends the functionality of an
existing type in .NET. An extension method is a static method to the existing
static class. We call an extension method in the same general way; there is no
difference in calling.
Feature and Property of Extension Methods
The following list contains basic features and properties of extension methods:
It is a static method.
It must be located in a static class.
It uses the "this" keyword as the first parameter with a type in .NET and this method will be called by a given type instance on the client side.
It also shown by VS intellisense. When we press the dot (.) after a type instance, then it comes in VS intellisense.
An extension method should be in the same namespace as it is used or you need to import the namespace of the class by a using statement.
You can give any name for the class that has an extension method but the class should be static.
If you want to add new methods to a type and you don't have the source code for it, then the solution is to use and implement extension methods of that type.
If you create extension methods that have the same signature methods as the type you are extending, then the extension methods will never be called.
Feature and Property of Extension Methods
The following list contains basic features and properties of extension methods:
It is a static method.
It must be located in a static class.
It uses the "this" keyword as the first parameter with a type in .NET and this method will be called by a given type instance on the client side.
It also shown by VS intellisense. When we press the dot (.) after a type instance, then it comes in VS intellisense.
An extension method should be in the same namespace as it is used or you need to import the namespace of the class by a using statement.
You can give any name for the class that has an extension method but the class should be static.
If you want to add new methods to a type and you don't have the source code for it, then the solution is to use and implement extension methods of that type.
If you create extension methods that have the same signature methods as the type you are extending, then the extension methods will never be called.
#
Definition
: An extension method has simplified calling syntax. It represents static
methods as instance methods. An extension method uses the this-keyword in its
parameter list. It must be located in a static class.
Example ::
this class has a field for the ProductName and for the ProductPrice.
namespace Products
{
public class Product
{
public string ProductName { get; set; }
public double ProductPrice { get; set; }
}
}
No problems so far, so you use this class in a list and display the name and price:
class Program
{
static void Main(string[] args)
{
List Products = new List()
{
new Product{ProductName = "White Shoe", ProductPrice = 10},
new Product{ProductName = "Green Shoe", ProductPrice = 5},
new Product{ProductName = "Black Shoe", ProductPrice = 15}
};
foreach (Product p in Products)
{
Console.WriteLine("{0} costs {1}", p.ProductName, p.ProductPrice);
}
}
}
Now you realize it would be great to display how much the VAT (tax) is of the price as well.
However, you do not own or have control over the Product class since it is owned by someone else. So you can't add a CalculateVat() method to the product class.
You could of course, in code above, display it like so:
foreach (Product p in Products)
{
Console.WriteLine("{0} costs {1} (VAT: {2})", p.ProductName, p.ProductPrice, (p.ProductPrice * .25));
}
This however requires you to do it everywhere you display this, and if the VAT changes, you have to edit the value everywhere, so it would be much nicer
to have this as a method on the Product class directly instead. Enter the Extension method.
This is as simple as this, define a static class, declare a static method that does what you want to do. The method should take as an argument the class
we want to add the method to and it has to be prefixed with the THIS keyword. Like so:
public static class MyExtensions
{
public static double CalculateVat(this Product p)
{
return (p.ProductPrice * .25);
}
}
That is all that is needed, we can now call the Extension method :
foreach (Product p in Products)
{
Console.WriteLine("{0} costs {1} (VAT: {2})", p.ProductName, p.ProductPrice, p.CalculateVat());
}
Example ::
this class has a field for the ProductName and for the ProductPrice.
namespace Products
{
public class Product
{
public string ProductName { get; set; }
public double ProductPrice { get; set; }
}
}
No problems so far, so you use this class in a list and display the name and price:
class Program
{
static void Main(string[] args)
{
List Products = new List()
{
new Product{ProductName = "White Shoe", ProductPrice = 10},
new Product{ProductName = "Green Shoe", ProductPrice = 5},
new Product{ProductName = "Black Shoe", ProductPrice = 15}
};
foreach (Product p in Products)
{
Console.WriteLine("{0} costs {1}", p.ProductName, p.ProductPrice);
}
}
}
Now you realize it would be great to display how much the VAT (tax) is of the price as well.
However, you do not own or have control over the Product class since it is owned by someone else. So you can't add a CalculateVat() method to the product class.
You could of course, in code above, display it like so:
foreach (Product p in Products)
{
Console.WriteLine("{0} costs {1} (VAT: {2})", p.ProductName, p.ProductPrice, (p.ProductPrice * .25));
}
This however requires you to do it everywhere you display this, and if the VAT changes, you have to edit the value everywhere, so it would be much nicer
to have this as a method on the Product class directly instead. Enter the Extension method.
This is as simple as this, define a static class, declare a static method that does what you want to do. The method should take as an argument the class
we want to add the method to and it has to be prefixed with the THIS keyword. Like so:
public static class MyExtensions
{
public static double CalculateVat(this Product p)
{
return (p.ProductPrice * .25);
}
}
That is all that is needed, we can now call the Extension method :
foreach (Product p in Products)
{
Console.WriteLine("{0} costs {1} (VAT: {2})", p.ProductName, p.ProductPrice, p.CalculateVat());
}
S
stands for SRP (Single responsibility principle
O stands for OCP (Open closed principle)
L stands for LSP (Liskov substitution principle)
I stands for ISP ( Interface segregation principle)
D stands for DIP ( Dependency inversion principle)
O stands for OCP (Open closed principle)
L stands for LSP (Liskov substitution principle)
I stands for ISP ( Interface segregation principle)
D stands for DIP ( Dependency inversion principle)
Yes.
primitive type is a data
type in c# language which is understandable by the C# compiler . in C# int ,
string , float etc... data types are considered as primitive types . during
compilation usually primitive types are converted into MSIL types.
Ex: if you write int x=20
; in C# language during compilation the code is converted as shown below .
Int32 x=20;
Note: Int32 is MSIL
equivalent for int primitive type . question copied from below weblink .
1-Chart,
WebGrid, Crypto,WebImage, WebMail Controls All these are available in MVC3 and
in MVC4.
2-TempData, ViewData ,ViewBag are available in MVC4.
3-MVC4 provides better support for Jquery like Jquery Mobile.
2-TempData, ViewData ,ViewBag are available in MVC4.
3-MVC4 provides better support for Jquery like Jquery Mobile.
#
1.Bundling
and minifications
2.Web API
3.Mobile Application support and mobile application template.
2.Web API
3.Mobile Application support and mobile application template.
#
1.Bundling
and minifications
2.Web API
3.Mobile Application support and mobile application template.
2.Web API
3.Mobile Application support and mobile application template.
#
1.Bundling
and minifications
2.Web API
3.Mobile Application support and mobile application template.
2.Web API
3.Mobile Application support and mobile application template.
#
1.
Display Model.
2. Web API.
3. Mobile Application Template.
4.Using Asynchronous Controllers etc
2. Web API.
3. Mobile Application Template.
4.Using Asynchronous Controllers etc
1. implement
methods with filly qualified name e.g. I1.GetdEscription() where I1 is the
interface
2. You need to explicitly cast your call instance to the interface you want to call and call the method
2. You need to explicitly cast your call instance to the interface you want to call and call the method
#
For
Example, If you are having two interfaces are named as,
public interface IA
{
void XYZ();
}
public interface IB
{
void XYZ();
}
And you can implement these two interfaces in a class as below,
public class C1
{
public void IA.XYZ()
{
//something IA
}
public void IB.XYZ()
{
//something IB
}
}
Now you can call these methods as below,
IA obj1 = new C1();
IB obj2 = new C1();
obj1.XYZ(); // calls the method of interface IA
obj2.XYZ(); // calls the method of interface IB
public interface IA
{
void XYZ();
}
public interface IB
{
void XYZ();
}
And you can implement these two interfaces in a class as below,
public class C1
{
public void IA.XYZ()
{
//something IA
}
public void IB.XYZ()
{
//something IB
}
}
Now you can call these methods as below,
IA obj1 = new C1();
IB obj2 = new C1();
obj1.XYZ(); // calls the method of interface IA
obj2.XYZ(); // calls the method of interface IB
A
delegate is a type that references a method. Once a delegate is assigned a
method, it behaves exactly like that method. The delegate method can be used
like any other method, with parameters and a return value, as in this example:
public delegate int PerformCalculation(int x, int y);
public delegate int PerformCalculation(int x, int y);
The
size of the reference itself will depend on your processor architecture - 4
bytes on 32-bit, 8 bytes on 64-bit.
All references are the same size (they are 4 bytes on a
32-bit CLR and 8 bytes on a 64-bit CLR, but within any one CLR all references
are the same size)
Dictionary is a
generic type, allowing:
static typing (and compile-time verification)
use without boxing
If you are .NET 2.0 or above, you should prefer Dictionary (and the other generic collections)
A subtle but important difference is that Hashtable supports
multiple reader threads with a single writer thread, while Dictionary offers no
thread safety. If you need thread safety with a generic dictionary, you must
implement your own synchronization or (in .NET 4.0) use ConcurrentDictionary.
Dictionary is typed (so valuetypes don't need boxing), a
Hashtable isn't (so valuetypes need boxing).
#
Dictionary
and Hash table are collection of data structure to hold data as key-value
pairs.
Dictionary is generic type, hash table is not generic type.
We can't use dictionary with web services.
In .NET hash table is thread safe for use by multiple reader thread and a single writing thread, while in dictionary public static members are thread safe, but any instance members are not guaranteed to be thread safe.
Dictionary is generic type, hash table is not generic type.
We can't use dictionary with web services.
In .NET hash table is thread safe for use by multiple reader thread and a single writing thread, while in dictionary public static members are thread safe, but any instance members are not guaranteed to be thread safe.
A 'using' statement is always better because
a) you can't forget to call Dispose, even as the code evolves
into different code paths, and
b) Dispose gets called even if there's an exception. It also
checks for null before calling Dispose, which may be useful.
The only place you don't want to use a using block is where the
disposable object is scoped outside of the function. In this case, your class
should implement IDisposable and dispose of the object in its Dispose()
A
reference type is storeed as a reference (like a pointer) to an object
instance.
null means a reference that isn't pointing to an instance of an object.
Value types are stored as the values themselves, without any references.
Therefore, it doesn't make sense to have a null value type—the value type by definition contains a value.
null means a reference that isn't pointing to an instance of an object.
Value types are stored as the values themselves, without any references.
Therefore, it doesn't make sense to have a null value type—the value type by definition contains a value.
#
Variables
that are based on value types directly contain values. Assigning one value type
variable to another copies the contained value. This differs from the
assignment of reference type variables, which copies a reference to the object
but not the object itself.
All value types are derived implicitly from the System.ValueType.
Nullable is a value type with a HasValue flag that can be false to indicate that there is no value. It still has a value (when HasValue is false, Value is default(T)), but the HasValue flag tells you to ignore the value.
It has nothing to do with null, except that the CLR automatically unboxes null boxed values to a Nullable with HasValue set to false.
All value types are derived implicitly from the System.ValueType.
Nullable is a value type with a HasValue flag that can be false to indicate that there is no value. It still has a value (when HasValue is false, Value is default(T)), but the HasValue flag tells you to ignore the value.
It has nothing to do with null, except that the CLR automatically unboxes null boxed values to a Nullable with HasValue set to false.
We
cannot serialize dictionary. Key Value pair cannot be serialized.
XMLSerializer
is introduced in .NET 1.0 and specially designed for working with ASMX
services.
As per the design, it requires to serialize only public properties.
Also, XMLSerializer depends on the serialization assembly generated during run-time. XMLSerializer uses this runtime-generated assembly to serialize types. Doesn't use reflection. Hence, private variables are not serialized.
As per the design, it requires to serialize only public properties.
Also, XMLSerializer depends on the serialization assembly generated during run-time. XMLSerializer uses this runtime-generated assembly to serialize types. Doesn't use reflection. Hence, private variables are not serialized.
IComparer
interface implements the Compare method which can be used compare objects of
different types. IComparable interface implements the CompareTo method which
can be used to compare objects of same types.
IEnumerable is an interface
that defines one method GetEnumerator which returns an IEnumeratorinterface,
this in
turn allows readonly access to a collection. A collection that implements
IEnumerable can be used with a foreach statement.
What is the difference between static class and singleton?
turn allows readonly access to a collection. A collection that implements
IEnumerable can be used with a foreach statement.
What is the difference between static class and singleton?
Static classes and singletons both provide sharing of
redundant
objects in memory, but they are very different in usage and implementation.
Static Class:
objects in memory, but they are very different in usage and implementation.
Static Class:
You cannot create the instance of static class.
Loaded automatically by the .NET Framework common
language runtime
(CLR) when the program or namespace containing the class is loaded.
(CLR) when the program or namespace containing the class is loaded.
Static Class cannot have constructor.
we cannot pass the static class to method
We cannot inherit Static class to another Static class in
C#.
Singleton:
Singleton:
You can create one instance of the object and reuse it.
Singleton instance is created for the first time
when the user requested.
singleton class can have constructor.
you can create the object of singleton class and pass it
to method
Singleton class does not say any restriction of
Inheritance.
We can dispose the objects of a singleton class but not of static
class
They are
generic types that help cut down on delegate type declarations. Whereas
previously, you'd have to declare your own delegate type for, say, this
delegate:
public delegate int MyDelegate(int arg1, double arg2, string arg3);
public MyDelegate mInstance;
You can now declare
the instance like this:
public Func mInstance;
Without having
to declare the delegate type. The Action<> delegate is the exact
same thing, except for delegates that return void.
generic types that help cut down on delegate type declarations. Whereas
previously, you'd have to declare your own delegate type for, say, this
delegate:
public delegate int MyDelegate(int arg1, double arg2, string arg3);
public MyDelegate mInstance;
You can now declare
the instance like this:
public Func mInstance;
Without having
to declare the delegate type. The Action<> delegate is the exact
same thing, except for delegates that return void.
#
Action
and Func are Generic Delegates in C#
Action is a generic Delegate that does not accept any Paramter Input not returns a value.
Func is a generic Delegate that accepts Input Parameter and has a return type.
General form :
Func myFuncDel;
Action is a generic Delegate that does not accept any Paramter Input not returns a value.
Func is a generic Delegate that accepts Input Parameter and has a return type.
General form :
Func myFuncDel;
Application
pool and AppDomain , both of them can provide isolations, but use different
approches.
Application pool use the process to isolate the applications which works without .NET. While AppDomain is another isolation methods provided by .NET.
If your server host thousands of web sites, you won't use thousands of the application pool to isolate the web sites, just because, too many processes running will kill the Operating System. However, sometime you need application pool. One of the advantages for application pool is that you can config the identity for application pool. Also you have more flexible options to recyle the application pool. At least right now, IIS didn't provide explicit options to recyle the appdomain.
An application pool is a group of one or more URLs of different Web applications and Web sites. Any Web directory or virtual directory can be assigned to an application pool. Every application within an application pool shares the same worker process executable, W3wp.exe, the worker process that services one application pool is separated from the worker process that services
Application pool use the process to isolate the applications which works without .NET. While AppDomain is another isolation methods provided by .NET.
If your server host thousands of web sites, you won't use thousands of the application pool to isolate the web sites, just because, too many processes running will kill the Operating System. However, sometime you need application pool. One of the advantages for application pool is that you can config the identity for application pool. Also you have more flexible options to recyle the application pool. At least right now, IIS didn't provide explicit options to recyle the appdomain.
An application pool is a group of one or more URLs of different Web applications and Web sites. Any Web directory or virtual directory can be assigned to an application pool. Every application within an application pool shares the same worker process executable, W3wp.exe, the worker process that services one application pool is separated from the worker process that services
#
Application
domain is one in which an application runs and application pool is one which
will be controlled by IIS. In IIS 4/5 we have only one application pool where
as in IIS 6 we can have more than 2,400 application pools.
The life cycle of an ASP.NET application starts with a request
sent by a browser to the Web server (for ASP.NET applications, typically IIS).
ASP.NET is an ISAPI extension under the Web server. When a Web server receives
a request, it examines the file name extension of the requested file, determines
which ISAPI extension should handle the request, and then passes the request to
the appropriate ISAPI extension. ASP.NET handles file name extensions that have
been mapped to it, such as .aspx, .ascx, .ashx, and .asmx.
If a file name extension has not been mapped to ASP.NET, then
ASP.NET will not receive the request. This is important to understand for
applications that use ASP.NET authentication. For example, because .htm files
are typically not mapped to ASP.NET, ASP.NET will not perform authentication or
authorization checks on requests for .htm files. Therefore, even if a file
contains only static content, if you want ASP.NET to check authentication,
create the file using a file name extension mapped to ASP.NET, such as .aspx.If
you create a custom handler to service a particular file name extension, you
must map the extension to ASP.NET in IIS and also register the handler in your
application's Web.config file.
readonly: This is the
Runtime constant. We can initialize the values once through constructor(while running).
constant: Constant value
is initialized at compile time. We can not initialize the constant values at compile time.
#
A const
must be initialized at the time of its creation. A readonly field can be
assigned to once in the class constructor allowing you to pass in the value at
run-time. Declaring fields as const protects both you and other programmers
from accidentally changing the value of the field. Also note that with const
fields, the compiler performs some optimization by not declaring any stack
space for the field. The readonly keyword is similar to const, with two
exceptions. First, the storage of a readonly field is the same as a regular
read-write field, and thus there is no performance benefit. Secondly, readonly
fields can be initialized in the constructor of the containing class.
#
Constants
:- it's value set at compile time and support value types
Static readonly:it's value set at run time and are able to hold refrence types
Static readonly:it's value set at run time and are able to hold refrence types
The
AsyncController class enables you to write asynchronous action methods. You can
use asynchronous action methods for long-running, non-CPU bound requests. This
avoids blocking the Web server from performing work while the request is being
processed.
The
View-Model is a composite of the abstraction of you view's state and behavior.
The idea behind the
View-Model is to create an abstraction of your view which has little to no dependencies on your view.
There should be no references to UI controls or classes specific to the UI. There should be no event
handlers like what is common in a code-behind class.
For example, If a Customer object has fifty properties, but one component only shows their name, then we create a custom ViewModel type with only those two properties. Because we only have one ViewModel type per
View, we shape our ViewModel around only what is displayed (or used) in that View.
For one, just having a ViewModel points us to the right View. We need any other information other than your ViewModel type to pick the correct View. This also means we no longer need to concern ourselves with locating views by some arbitrary name, as the ViewModel is the View. Things like RenderPartial,which I have to select a name, become rather pointless at that point.
View-Model is to create an abstraction of your view which has little to no dependencies on your view.
There should be no references to UI controls or classes specific to the UI. There should be no event
handlers like what is common in a code-behind class.
For example, If a Customer object has fifty properties, but one component only shows their name, then we create a custom ViewModel type with only those two properties. Because we only have one ViewModel type per
View, we shape our ViewModel around only what is displayed (or used) in that View.
For one, just having a ViewModel points us to the right View. We need any other information other than your ViewModel type to pick the correct View. This also means we no longer need to concern ourselves with locating views by some arbitrary name, as the ViewModel is the View. Things like RenderPartial,which I have to select a name, become rather pointless at that point.
#
View
Model in MVC is used in situation where we want to use the multiple model
instance in single form or view page.
View model will have the multiple model property. Those properties can be used using Razor syntax and in the Controller post action we can separate the properties into required individual model and save the data into different model simultaneously.
View model will have the multiple model property. Those properties can be used using Razor syntax and in the Controller post action we can separate the properties into required individual model and save the data into different model simultaneously.
Code
First: In the Code First approach, you avoid working with visual model designer
(EDMX) completely. You write your POCO classes first and then create database
from these POCO classes. Developers who follow the path of Domain-Driven Design
(DDD) principles prefer to begin by coding their classes first and then
generating the database required to persist their data.
#
In
Entity Frame work Code First means ,you directly write POCO Classes.
Data base is created from this POCO Classes.
Data base is created from this POCO Classes.
Prior
to ASP.NET MVC 5, there are 4 types of filters:
1. Authorization filters (IAuthorizationFilter)
2. Action filters (IActionFilter)
3. Result filters (IResultFilter)
4. Exception filters (IExceptionFilter)
ASP.NET MVC 5 introduces the new Authentication filters (IAuthenticationFilter).
1. Authorization filters (IAuthorizationFilter)
2. Action filters (IActionFilter)
3. Result filters (IResultFilter)
4. Exception filters (IExceptionFilter)
ASP.NET MVC 5 introduces the new Authentication filters (IAuthenticationFilter).
ASP.NET
MVC supports the following types of action filters:
1.
Authorization
filters. These implement IAuthorizationFilter and make security
decisions about whether to execute an action method, such as performing
authentication or validating properties of the request. The AuthorizeAttribute class and theRequireHttpsAttribute class are examples of an authorization
filter. Authorization filters run before any other filter.
2.
Action
filters. These implement IActionFilter and wrap the action method
execution. The IActionFilter interface declares two
methods: OnActionExecuting and OnActionExecuted. OnActionExecuting runs before the action method. OnActionExecuted runs after the action
method and can perform additional processing, such as providing extra data to
the action method, inspecting the return value, or canceling execution of the
action method.
3.
Result
filters. These implement IResultFilter and wrap execution of the ActionResult object. IResultFilter declares two methods: OnResultExecuting and OnResultExecuted. OnResultExecuting runs before the ActionResult object is executed. OnResultExecuted runs after the result
and can perform additional processing of the result, such as modifying the HTTP
response. The OutputCacheAttribute class is one example
of a result filter.
4.
Exception
filters. These implement IExceptionFilter and execute if there is
an unhandled exception thrown during the execution of the ASP.NET MVC pipeline.
Exception filters can be used for tasks such as logging or displaying an error
page. TheHandleErrorAttribute class is one example of an exception
filter.
MVC is
design pattern and it's introduced for to separate the UI (User Interface) from
ASP.Net.
MVC is
an architectural design pattern that define the whole application design and
structure.
MVC is
itself a pattern(architectural design pattern).
Razor
is new view engine came with MVC3 . It gives cleaner syntax and render clean
HTML in comparison of Web Forms. Razor syntax is quit different from Web Form
or classic asp.
#
Aspx
View Engine - This view engine present in MVC 1 and MVC2. Whatever code you
want to write in View you need specify like <% string str =
"India" %>
Razor Veiw Engine- It is supported in versions after MVC3. SYntax for this is like @for(int i=0;i<5;i++) {}
Razor view engine code is more concise and clean than aspx view engine.
There are mostly syntactical differences between these two view engines.
Razor Veiw Engine- It is supported in versions after MVC3. SYntax for this is like @for(int i=0;i<5;i++) {}
Razor view engine code is more concise and clean than aspx view engine.
There are mostly syntactical differences between these two view engines.
When a
matching pattern found in the Route Table, the Routing engine forwards the
request to the corresponding IRouteHandler for that request. The default one
calls the MvcHandler
The
main difference between Partial and RenderPartial is :
Partial return string and write it to document as Shweta said . RenderPartial actually write direct to context response.
Partial return string and write it to document as Shweta said . RenderPartial actually write direct to context response.
#
The
basic usage is:
// Razor syntax
@Html.Partial("ViewName")
@{ Html.RenderPartial("ViewName"); }
// WebView syntax
<%: Html.Partial("ViewName") %>
<% Html.RenderPartial("ViewName"); %>
In the snippet above, both calls will yield the same result.
While one can store the output of Html.Partial in a variable or return it from a method, one cannot do this with Html.RenderPartial. The result will be written to the Response stream during execution/evaluation.
// Razor syntax
@Html.Partial("ViewName")
@{ Html.RenderPartial("ViewName"); }
// WebView syntax
<%: Html.Partial("ViewName") %>
<% Html.RenderPartial("ViewName"); %>
In the snippet above, both calls will yield the same result.
While one can store the output of Html.Partial in a variable or return it from a method, one cannot do this with Html.RenderPartial. The result will be written to the Response stream during execution/evaluation.
#
The
main difference is that "RenderPartial" returns void and output will
be written directly to the output sream,
where as the "Partial" returns MvcHtmlString which can be assigned to a variable and manipulate it if required.
So, when there is no need to assign the output to a variable for manipulating it, then use Partial, else use
RenderPartial.
Renderpartial does exactly the same thing and is better for performance over partial().
where as the "Partial" returns MvcHtmlString which can be assigned to a variable and manipulate it if required.
So, when there is no need to assign the output to a variable for manipulating it, then use Partial, else use
RenderPartial.
Renderpartial does exactly the same thing and is better for performance over partial().
Html.BeginForm()
will create a form on the page that submits its values to the server as a
synchronous HTTP request, refreshing the entire page in the process.
Ajax.BeginForm() creates a form that submits its values using an asynchronous
ajax request. This allows a portion of the page to be update without requiring
that the entire page be refreshed.
#
Ajax:
1. Won't redirect the form even you do a RedirectAction().
2. Will perform save , update and any modification operations asynchronously.
3. Validate the Form using FormMethods - OnSubmit. So you are abort the Post
4. This creates a form that submits its values using an asynchronous ajax request. This allows a portion of the page to be update without requiring that the entire page be refreshed.
Html :
1. Will redirect the form.
2. Will perform operations both Synchronously and Asynchronously (With some extra code and care).
3. Html.BeginForm will always use RouteTable to detrmine the action attribute value.
4. This will create a form on the page that submits its values to the server as a synchronous HTTP request, refreshing the entire page in the process.
1. Won't redirect the form even you do a RedirectAction().
2. Will perform save , update and any modification operations asynchronously.
3. Validate the Form using FormMethods - OnSubmit. So you are abort the Post
4. This creates a form that submits its values using an asynchronous ajax request. This allows a portion of the page to be update without requiring that the entire page be refreshed.
Html :
1. Will redirect the form.
2. Will perform operations both Synchronously and Asynchronously (With some extra code and care).
3. Html.BeginForm will always use RouteTable to detrmine the action attribute value.
4. This will create a form on the page that submits its values to the server as a synchronous HTTP request, refreshing the entire page in the process.
System.ComponentModel.DataAnnotations
Namespace
#
If you
want to perform model validation using DataAnnotations Attributes, you must
include System.ComponentModel.DataAnnotations name space.
there are many DataAnnotation attributes are in MVC for validation
there are many DataAnnotation attributes are in MVC for validation
what is
strongly typed view in Asp.Net MVC?
Strongly
typed views are used for rendering specific types of model objects. By
specifying type of data, visual studio provides intellisense for that class.
View inherits from ViewPage whereas strongly typed view inherits from ViewPage where T is type of the model.
#
It is
view that is render using specific types of model objects.
@model Project.MyModel
In this template we get the intellisense support.
Strongly-typed view has following advantages.
1) Intellisense
2) Compile time type checking
3) Automatic scaffolding
@model Project.MyModel
In this template we get the intellisense support.
Strongly-typed view has following advantages.
1) Intellisense
2) Compile time type checking
3) Automatic scaffolding
A Strongly Typed view
means it has a ViewModel associated to it that the controller is passing to it
and all the elements in that View can use those ViewModel properties
You can have strongly typed partials as well. Meaning that piece of Html needs specific data so you type it to a certain ViewModel
Here is an example of a Strongly Typed View
@model SomeViewModel
...// all the html comes after
A view that is strongly typed have a @model SomeViewModel line
Here's one that renders a strongly typed View
public ActionResult Index() {
var model = new SomeViewModel();
return View(model);
}
And the view makes use of that ViewModel by having the @model SomeViewModel at the top of the file.
So now that the view has a ViewModel I can display elements that are bound to the ViewModel like
You can have strongly typed partials as well. Meaning that piece of Html needs specific data so you type it to a certain ViewModel
Here is an example of a Strongly Typed View
@model SomeViewModel
...// all the html comes after
A view that is strongly typed have a @model SomeViewModel line
Here's one that renders a strongly typed View
public ActionResult Index() {
var model = new SomeViewModel();
return View(model);
}
And the view makes use of that ViewModel by having the @model SomeViewModel at the top of the file.
So now that the view has a ViewModel I can display elements that are bound to the ViewModel like
@Model.Name
@Model.Location
OR for Controls------
@Html.TextBoxFor(m => m.Name)
@Html.TextBoxFor(m => m.Location)
http://www.c-sharpcorner.com/Interviews/category/226/Asp-Net-mvc-interview-questions
Using Nullable Types (C# Programming Guide)
Visual Studio 2013
Nullable
types can represent all the values of an underlying type, and an additional null value. Nullable types are declared in
one of two ways:
System.Nullable<T> variable
-or-
T? variable
T is
the underlying type of the nullable type. T can
be any value type including struct; it cannot be a reference type.
For
an example of when you might use a nullable type, consider how an ordinary
Boolean variable can have two values: true and false. There is no value that
signifies "undefined". In many programming applications, most notably
database interactions, variables can occur in an undefined state. For example,
a field in a database may contain the values true or false, but it may also
contain no value at all. Similarly, reference types can be set to null to indicate that they are not
initialized.
This
disparity can create extra programming work, with additional variables used to
store state information, the use of special values, and so on. The nullable
type modifier enables C# to create value-type variables that indicate an undefined
value.
Examples of Nullable Types
Any
value type may be used as the basis for a nullable type. For example:
C#
int? i = 10;
double? d1 = 3.14;
bool? flag = null;
char? letter = 'a';
int?[] arr = new int?[10];
The Members of Nullable Types
Each
instance of a nullable type has two public read-only properties:
·
HasValue
HasValue is
of type bool.
It is set to true when the variable contains a non-null
value.
·
Value
Value is
of the same type as the underlying type. If HasValue is true, Value contains a meaningful value. If HasValue is false,
accessing Value will throw aInvalidOperationException.
In
this example, the HasValue member is used to test whether the
variable contains a value before it tries to display it.
C#
int? x = 10;
if (x.HasValue)
{
System.Console.WriteLine(x.Value);
}
else
{
System.Console.WriteLine("Undefined");
}
Testing
for a value can also be done as in the following example:
C#
int? y = 10;
if (y != null)
{
System.Console.WriteLine(y.Value);
}
else
{
System.Console.WriteLine("Undefined");
}
Explicit Conversions
A nullable type can
be cast to a regular type, either explicitly with a cast, or by using the Value property. For example:
C#
int? n = null;
//int m1 = n; // Will not compile.
int m2 = (int)n; // Compiles, but will create an exception if n is null.
int m3 = n.Value; // Compiles, but will create an exception if n is null.
If a user-defined
conversion is defined between two data types, the same conversion can also be
used with the nullable versions of these data types.
Implicit Conversions
A variable of
nullable type can be set to null with the null keyword,
as shown in the following example:
C#
int? n1 = null;
The conversion from
an ordinary type to a nullable type, is implicit.
C#
int? n2;
n2 = 10; // Implicit conversion.
Operators
The predefined unary
and binary operators and any user-defined operators that exist for value types
may also be used by nullable types. These operators produce a null value if the
operands are null; otherwise, the operator uses the contained value to
calculate the result. For example:
C#
int? a = 10;
int? b = null;
a++; // Increment by 1, now a is 11.
a = a * 10; // Multiply by 10, now a is 110.
a = a + b; // Add b, now a is null.
When you perform
comparisons with nullable types, if the value of one of the nullable types is
null and the other is not, all comparisons evaluate to false except for != (not equal). It is important not to
assume that because a particular comparison returns false,
the opposite case returns true. In the following example, 10 is not greater
than, less than, nor equal to null. Only num1 != num2 evaluates to true.
C#
int? num1 = 10;
int? num2 = null;
if (num1 >= num2)
{
Console.WriteLine("num1 is greater than or equal to num2");
}
else
{
// This clause is selected, but num1 is not less than num2.
Console.WriteLine("num1 >= num2 returned false (but num1 < num2 also is false)");
}
if (num1 < num2)
{
Console.WriteLine("num1 is less than num2");
}
else
{
// The else clause is selected again, but num1 is not greater than
// or equal to num2.
Console.WriteLine("num1 < num2 returned false (but num1 >= num2 also is false)");
}
if (num1 != num2)
{
// This comparison is true, num1 and num2 are not equal.
Console.WriteLine("Finally, num1 != num2 returns true!");
}
// Change the value of num1, so that both num1 and num2 are null.
num1 = null;
if (num1 == num2)
{
// The equality comparison returns true when both operands are null.
Console.WriteLine("num1 == num2 returns true when the value of each is null");
}
/* Output:
* num1 >= num2 returned false (but num1 < num2 also is false)
* num1 < num2 returned false (but num1 >= num2 also is false)
* Finally, num1 != num2 returns true!
* num1 == num2 returns true when the value of each is null
*/
An equality
comparison of two nullable types that are both null evaluates to true.
The ?? Operator
The ?? operator defines a default value that
is returned when a nullable type is assigned to a non-nullable type.
C#
int? c = null;
// d = c, unless c is null, in which case d = -1.
int d = c ?? -1;
This operator can
also be used with multiple nullable types. For example:
C#
int? e = null;
int? f = null;
// g = e or f, unless e and f are both null, in which case g = -1.
int g = e ?? f ?? -1;
The bool? type
The bool? nullable type can contain three
different values: true, false and null. For information
about how to cast from a bool? to a bool, see How to: Safely Cast
from bool? to bool (C# Programming Guide).
Nullable Booleans are
like the Boolean variable type that is used in SQL. To ensure that the results
produced by the & and | operators are consistent with the
three-valued Boolean type in SQL, the following predefined operators are
provided:
bool? operator &(bool? x, bool? y)
bool? operator |(bool? x, bool? y)
SINGLETON
PATTERN EXP.
using
System;
public
class Singleton
{
private static Singleton instance;
private Singleton() {}
public static Singleton Instance
{
get
{
if (instance == null)
{
instance = new Singleton();
}
return instance;
}
}
}
No comments:
Post a Comment