Posts

Difference between Html.Partial and Html.RenderPartial and Html.Action and Html.RenderAction

Html.Partial returns MVCHtmlString which can be assigned to a variable and manipulate if required. Syntax :  @Html.Partial("ViewName") Html.RenderPartial returns void and output will be written directly to the output stream. Syntax :  @{ Html.RenderPartial("ViewName"); } Note:  We can also pass the model to the Partial Syntax :  @Html.Partial("ViewName", Model)                 @{ Html.RenderPartial("ViewName", Model)  } Html.Action  Invokes the specified child action method and returns the result as an HTML string Syntax :  @{string result = @Html.Action("Action", "Controller", new { param = "value"} ).ToString();} Html.RenderAction  Invokes the specified child action method and renders the result inline in the parent view. Syntax :  @{ Html.Action("Action", "Controller", new { param = "value"} ).ToString();} Note:  This method is faster than t...

Difference between MVC version

MVC6 ASP.NET MVC and Web API has been merged in to one. Dependency injection is inbuilt and part of MVC. No need to recompile for every change. Just hit save and refresh the browser. MVC5 One ASP.NET Attribute based routing Asp.Net Identity Bootstrap in the MVC template Authentication Filters Filter overrides MVC4 ASP.NET Web API Refreshed and modernized default project templates New mobile project template Many new features to support mobile apps Enhanced support for asynchronous methods MVC3 Razor Readymade project templates HTML 5 enabled templates Support for Multiple View Engines JavaScript and Ajax Model Validation Improvements MVC2 Client-Side Validation Templated Helpers Areas Asynchronous Controllers Html.ValidationSummary Helper Method DefaultValueAttribute in Action-Method Parameters Binding Binary Data with Model Binders DataAnnotations Attributes Model-Validator Providers New RequireHttpsAttribute Act...

Hashset, HashTable in c#

Image
HashSet -  This is an optimized set collection. It helps eliminates duplicate strings or elements in an array. This internally calls the UnionWith method to eliminate the duplications.  It has OverLap,  SymmetricExceptWith OverLap - This method returns true or false. It tests to see if any of the HashSet's elements are contained in the IEnumerable argument's elements. Only one equal element is required. SymmetricExceptWith - This method returns only those don't match in the collection. HashTable - The  Hashtable  class represents a collection of key-and-value pairs that are organized based on the  hash  code of the key. It uses the key to access the elements in the collection.  A  hash table  is used when you need to access elements by using key, and you can identify a useful key value. This optimizes lookups. It computes a hash of each key you add. It then uses this hash code to look up the element ver...

Difference between IEnumerable, ICollection, IList and List in c#

IEnumerable<T>  is the base interface that the following extend or implement. It doesn't allow for direct access and is readonly. So use this only if you intend to iterate over the collection. ICollection<T>  extends IEnumerable<T>  but in addition allows for adding, removing, testing whether an element is present in the collection and getting the total number of elements. It doesn't allow for directly accessing an element by index. That would be an O(n) operation as you need to start iterating over it until you find the corresponding element. IList<T>  extends  ICollection<T>  (and thus it inherits all its properties) but in addition allows for directly accessing elements by index. It's an O(1) operation. List<T>  is just a concrete implementation of the  IList<T>  interface.

Await Async in c#

      It is introduced in .net framework 4.5.  async make the method asynchronous and await suspend the calling function and returns the control to the UI. There are two ways to implement async and await. I/O bound C# Copy private readonly HttpClient _httpClient = new HttpClient(); downloadButton.Clicked += async (o, e) => { // This line will yield control to the UI as the request // from the web service is happening. // // The UI thread is now free to perform other work. var stringData = await _httpClient.GetStringAsync(URL); DoSomethingWithData(stringData); }; CPU bound C# Copy private DamageResult CalculateDamageDone ( ) { // Code omitted: // // Does an expensive calculation and returns // the result of that calculation. } calculateButton.Clicked += async (o, e) => { // This line will yield control to the UI while CalculateDamageDone() // performs its work. The UI thread is f...

Asp.net and C# Interview Qustions

ASP.NET 1. Where machine.config resides? 32-bit % windir % \Microsoft . NET\Framework\[version ] \config\machine . config 64-bit % windir % \Microsoft . NET\Framework64\[version ] \config\machine . config [version]  should be equal to  v1.0.3705 ,  v1.1.4322 ,  v2.0.50727  or  v4.0.30319 . 2. How can we prevent browser from caching an ASPX page? We can SetNoStore on HttpCachePolicy object exposed by the Response object’s Cache property: 1 2 Response . Cache . SetNoStore ( ) ; Response . Write ( DateTime . Now . ToLongTimeString ( ) ) ; 3. Page Life cycle stages? Stage Description Page request The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled (therefore beginning the life of a page), or whether a cached version of the page can be sent in response without running the page. Start In the ...

How to get device info IMEI programmatically in xamarin android

You'll need the following permission in your  AndroidManifest.xml : <uses-permission android:name="android.permission.READ_PHONE_STATE" /> in order to do this. You want to call  android.telephony.TelephonyManager.getDeviceId() . This will return whatever string uniquely identifies the device (IMEI for GSM, MEID for CDMA). Code Android.Telephony.TelephonyManager mTelephonyMgr;             mTelephonyMgr = (Android.Telephony.TelephonyManager)GetSystemService(TelephonyService);   //IMEI number    String m_deviceId = mTelephonyMgr.DeviceId;