Friday, June 26, 2015

How to create a empty enumarable

We might have experienced in the MVC View, if we have Enumerable list is null  for dropdown or select box normally we get an exception.

In MVC Razor controls we need to make sure all enumerable properties of a view model object should be set by default as empty.

 

Example:

SelectedList list =  numerable.Empty<SelectedList>()

Tips:Convert coma separated string into Interger Array

Use “Array.ConvertAll “  convert string array to  integer array.

 

For example:

String  Items = “1,2,3,4”

1)      Convert into  array

String[] ItemsArray =  items.Split(‘,’);

2)      Convert into Integer Array

Int[] intItemsArray =  Array.ConvertAll(ItemsArray,Int.Parse );

 

 

Thanks,

Aravind

Wednesday, June 24, 2015

MVC VS MVP VS MVVM

MVC:

In MVC , M is a model which can hold logic to persists the data. V represents view it just responsible to display data  and C is controller .

C Is heart for the MVC. Controller is responsible to handle the incoming request and invoke the corresponding view by passing the model.

Controller can call multiple view by as per business logic .

MVP:

In MVP , P stands for presenter and Controller is replaced  by Presenter. Presenter is not responsible to handle the  input request. Presenter and View communicates with each other

thorough some interface. Presenter is responsible for handling all the requests made by the view and  Communicate with model and updates the view. In MVP , The Presenter

should associated with one View.

MVVM:

In MVVM, VM view model  is same as Presenter But VM can have multiple views. View has a reference to ViewModel and it supports two way binding.

 

 

All above design patterns are used to implement loosely coupled system which allows us achieve   extendibility, testability  and scalability .

 

 

MVC

Controllers:

A controller built using the MVC should

 

•             Contain the logic required to initialize the scope

 

•             Contain the logic/behaviors required by the view to present data from the scope

 

•             Contain the logic/behaviors required to update the scope based on user interaction

 

The controller should not

 

•             Contain logic that manipulates the DOM (that is the job of the view)

 

•             Contain logic that manages the persistence of data (that is the job of the model)

 

•             Manipulate data outside of the scope

 

Views:

•             Contain the logic and markup required to present data to the user

 

Views should not

 

•             Contain complex logic (this is better placed in a controller)

 

•             Contain logic that creates, stores, or manipulates the domain model

 

Models:

•             Contain the domain data

 

•             Contain the logic for creating, managing, and modifying the domain data (even if that means

 

executing remote logic via web services)

 

•             Provide a clean API that exposes the model data and operations on it

 

The model should not

 

•             Expose details of how the model data is obtained or managed (in other words, details of the

 

data storage mechanism or the remote web service should not be exposed to controllers and views)

 

•    Contain logic that transforms the model based on user interaction (because this is the

 

controller’s job)

 

•             Contain logic for displaying data to the user (this is the view’s job)

 

 

Tuesday, June 16, 2015

Potentially dangerous error in MVC

In general the web application  would not allow the special characters when posting the data to server to avoid injections.

 

There are two ways we can handle the scenario

 

1)      Don’t allow special characters : Provide user friendly message to the user. And this might be annoying to client sometimes it is required to enter special characters.

 

2)      Allow the special characters: Let allow the special characters and handle it using data scrubbing. Use proper encoding and  decoding techniques to handle special characters.  

In ASP.net  MVC  , we have to decorate “AllowHtml”  for a property requires a HTML. So that asp.net will handle it.

Monday, June 1, 2015

What Causes Finalize Methods to be called

Finalize method is called in the Following Events.

1.       When Generation[0] is Full on the managed heap.

2.       When the program force the Garbage collector by GC.Collect.

3.       When Windows reports low memory to the CLR, the CLR force the garbage collection.

4.       When ClR is Unloading as ApplicationDomain.

5.       CLR is shutting down

How to refresh/update Stored procedure in entity Framework

1)      Go to Model browser

2)      On Model Browser type Stored Procedure name looking to update

 

3)      Find all references and  delete from Model.

 

 

4)      Right click and Update Model



5)      Click the Stored procedure and Click on finish

6)