Friday, July 20, 2012

How To call Mvc Function With Json



    $(document).ready(function () {
        $("#ddlModelSeries").change(function () {

            var Mname = $(this).val();

            $.getJSON("AddModelSeries/LoadBrand", { id: Mname }, function (AreaData) {
                var select = $("#ddlBrand"); select.empty(); select.append($('
                $.each(AreaData, function (index, itemData) {

                    select.append($('
                        value: itemData.Value,
                        text: itemData.Text
                    }));
                });

            });

        });


    });

             



how to hide menu in mvc 3 on master page





@if(Session["username"] !=null)
    {
 

 
     
 @Html.ActionLink("Manange Step", "Index", "Adminmanage")
 &nbsp 
@Html.ActionLink("Manange Errorcode", "Index", "Admin")&nbsp&nbsp

 @Html.ActionLink("LogOut", "LogOn", "Account")&nbsp&nbsp
     

        }

how pass value from page to javascript with hidden varible


@model UFixnow.Models.ModelSeries
@{
    ViewBag.Title = "Index";
   Layout = "~/Views/Shared/_Adminlayout.cshtml";
    var id = Session["SeriesId1"];
}





Tuesday, July 10, 2012

oops Concepts



 Abstraction

The process of picking out (abstracting) common features of objects and procedures. A programmer would use abstraction, for example, to note that two functions perform almost the same task and can be combined into a single function. Abstraction is one of the most important techniques in software engineering and is closely related to two other important techniques -- encapsulation and information hiding. All three techniques are used to reduce complexity.



Difference between Struct and Class

Struct are Value type and are stored on stack, while Class are Reference type and are stored on heap.
Struct “do not support” inheritance, while class supports inheritance. However struct can implements interface.
Struct should be used when you want to use a small data structure, while Class is better choice for complex data structure.



Boxing and Un-Boxing

Boxing: means converting value-type to reference-type.

Eg:

int I = 20;

string s = I.ToSting();


UnBoxing: means converting reference-type to value-type.

Eg:

int I = 20;

string s = I.ToString(); //Box the int

int J = Convert.ToInt32(s); //UnBox it back to an int.


Note: Performance Overheads due to boxing and unboxing as the boxing makes a copy of value type from stack and place it inside an object of type System.Object in the heap.




http://dng-oops.blogspot.in/









Virtual Method

By declaring base class function as virtual, we allow the function to be overridden in any of derived class.

Eg:

Class parent

{

virtual void hello()

{ Console.WriteLine(“Hello from Parent”); }

}


Class child : parent

{

override void hello()

{ Console.WriteLine(“Hello from Child”); }

}


static void main()

{

parent objParent = new child();

objParent.hello();

}

//Output

Hello from Child.





Access Modifiers

Access Modifiers are keywords used to specify the declared accessibility of a member of a type.

Public is visible to everyone. A public member can be accessed using an instance of a class, by a class's internal code, and by any descendants of a class.


Private is hidden and usable only by the class itself. No code using a class instance can access a private member directly and neither can a descendant class.

Protected members are similar to private ones in that they are accessible only by the containing class. However, protected members also may be used by a descendant class. So members that are likely to be needed by a descendant class should be marked protected.




Encapsulation

Is the ability of an object to hide its data and methods from the rest of the world. It is one of the fundamental principles of OOPs.

Real time
e.g. / Ink is the important component in pen but it is hiding by some other material

Say we create a class, named Calculations. This class may contain a few members in the form of properties, events, fields or methods. Once the class is created, we may instantiate the class by creating an object out of it. The object acts as an instance of this class, the members of the class are not exposed to the outer world directly; rather, they are encapsulated by the class.

For example code

Public class Calculations
{
  private void fnMultiply(int x, int y)
  {
  return x * y;
  }
}
...
...
Calculations obj;
int Result;
Result = obj.fnMultiply(5,10)




ENCAPSULATION MEANS HIDING ALL THE INTERNAL DETAILS OF THE METHODS.

EXAMPLE cars and owners...
all the functions of cars are encapsulated with the owners..
No one else can access it...





Friday, June 8, 2012

how to set dropdownlist max item in asp net


Set these value in dropdown

onmouseover="this.size=4;"
onmouseout="this.size=1;"

Friday, March 23, 2012

what is CLR,JIT,GAC,GC


CLR means Common Language Runtime.It is  Major component of 
the .NET frameworkIt provides no of benefits to the 
developers such as Exception handling,Security,Debugging 
and Versioning.

Common Language Runtime is Runtime engine which converts 
Microsoft Intermediate Language in machine understandable 
code, it is similar to JVM in Java


working of CLR:-

When the .NET program is compiled, the output of the 
compiler is not an executable file but a file that contains 
a special type of code called  the Microsoft Intermediate 
Language (MSIL), which is a low-level set of instructions 
understood by the common language run time. This MSIL 
defines a set of portable instructions that are independent 
of any specific CPU. It's the job of the CLR to translate 
this Intermediate code into a executable code when the 
program is executed making the program to run in any 
environment for which the CLR is implemented. And that's 
how the .NET Framework achieves Portability. This MSIL is 
turned into executable code using a JIT (Just In Time) 
complier. The process goes like this, when .NET programs 
are executed, the CLR activates the JIT complier. The JIT 
complier converts MSIL into native code on a demand basis 
as each part of the program is needed. Thus the program 
executes as a native code even though it is compiled into 
MSIL making the program to run as fast as it would if it is 
compiled to native code but achieves the portability 
benefits of MSIL.

jit:

Before Microsoft intermediate language (MSIL) can be
executed, it must be converted by a .NET Framework
just-in-time (JIT) compiler to native code, which is
CPU-specific code that runs on the same computer
architecture as the JIT compiler. 
Rather than using time and memory to convert all the MSIL in
a portable executable (PE) file to native code, it converts
the MSIL as it is needed during execution and stores the
resulting native code so that it is accessible for
subsequent calls.

JIT compiler is a part of the runtime execution environment.
In Microsoft .NET there are three types of JIT compilers.

Pre-JIT : Pre-JIT compiles complete source code into native
code in a single compilation cycle. This is done at the time
of deployment of the application.

Econo-JIT : Econo-JIT compiles only those methods that are
called at runtime. However, these compiled methods are
removed when they are not required.

Normal-JIT : Normal-JIT compiles only those methods thar are
called at runtime.

What is GAC?
A shared assembly has version constraints. It is stored in the Global Assembly Cache (GAC). GAC is a repository of shared assemblies maintained by the .NET runtime. The shared assemblies may be used by many applications. To make an assembly a shared assembly, it has to be strongly named.
GC:
In .NET Garbage Collector maintained by CLR. The process of 
GC is reclaim the memory of objets which is no longer 
referenced by our program.Next thing is GC runs 
undeterministicly because of that we can't assure we the 
object will be released from the Heap Location

If there is any memory defeciency then only GC will called 
by CLR. GC always runs on the priority basis. If size of free 
memory is more, than GC runs on low priority basis.  And if 
memory becomes low than GC Starts running on high priority 
to free up the memory from those object which are no loger 
in used.

metadata: Metadata is information about a PE(Portable Executable)means information about Executable file

Sunday, January 15, 2012

dynamic sitemap in mvc 3


Getting the bits

As always, the bits are available on CodePlex: MvcSiteMapProvider 2.0.0
If you prefer to have the full source code, download the example application or check the source code tab on CodePlex.

Introduction


MvcSiteMapProvider is, as the name implies, an ASP.NET MVC SiteMapProvider implementation for the ASP.NET MVC framework. Targeted at ASP.NET MVC 2, it provides sitemap XML functionality and interoperability with the classic ASP.NET sitemap controls, like the SiteMapPath control for rendering breadcrumbs and the Menu control.
Based on areas, controller and action method names rather than hardcoded URL references, sitemap nodes are completely dynamic based on the routing engine used in an application. The dynamic character of ASP.NET MVC is followed in the MvcSiteMapProvider: there are numerous extensibility points that allow you to extend the basic functionality offered.


"MvcSiteMapProvider" enabled="true">
 
   
    "MvcSiteMapProvider"
         type="MvcSiteMapProvider.DefaultSiteMapProvider, MvcSiteMapProvider"
         siteMapFile="~/Mvc.Sitemap"
         securityTrimmingEnabled="true"
         enableLocalization="true"
         scanAssembliesForSiteMapNodes="true"
         skipAssemblyScanOn=""
         attributesToIgnore="bling"
         nodeKeyGenerator="MvcSiteMapProvider.DefaultNodeKeyGenerator, MvcSiteMapProvider"
         controllerTypeResolver="MvcSiteMapProvider.DefaultControllerTypeResolver, MvcSiteMapProvider"
         actionMethodParameterResolver="MvcSiteMapProvider.DefaultActionMethodParameterResolver, MvcSiteMapProvider"
         aclModule="MvcSiteMapProvider.DefaultAclModule, MvcSiteMapProvider"
         />
 

in site map





   
   
   
   
   
   
 
    dynamicNodeProvider="WhoTrackYou.Models.StoreDetailsDynamicNodeProvider, WhoTrackYou"/>
 

in page where you want to show site map use following function:

  • Html.MvcSiteMap().Menu() - Can be used to generate a menu
  • Html.MvcSiteMap().SubMenu() - Can be used to generate a submenu
  • Html.MvcSiteMap().SiteMap() - Can be used to generate a list of all pages in your sitemap
  • Html.MvcSiteMap().SiteMapPath() - Can be used to generate a so-called "breadcrumb trail"
  • Html.MvcSiteMap().SiteMapTitle() - Can be used to render the current SiteMap node's title 




The following attributes can be given on an XML node element:
Attribute Required? Default Description
title Yes (empty) The title of the node.
description No (empty) Description of the node.
area No (empty) The MVC area for the sitemap node. If not specified, it will be inherited from a node higher in the hierarchy.
controller Yes (empty) The MVC controller for the sitemap node. If not specified, it will be inherited from a node higher in the hierarchy.
action Yes (empty) The MVC action method for the sitemap node. If not specified, it will be inherited from a node higher in the hierarchy.
key No (autogenerated) The unique identifier for the node.
url No (autogenerated based on routes) The URL represented by the node.
roles No (empty) Comma-separated list of roles allowed to access the node and its child nodes.
resourceKey No (empty) Optional resource key.
clickable No True Is the node clickable or just a grouping node?
targetFrame No (empty) Optional target frame for the node link.
imageUrl No (empty) Optional image to be shown by supported HtmlHelpers.
lastModifiedDate No (empty) Last modified date for the node.
changeFrequency No Undefined Change frequency for the node.
updatePriority No Undefined Update priority for the node.
dynamicNodeProvider No (empty) A class name implementing MvcSiteMapProvider.Extensibility.IDynamicNodeProvider and providing dynamic nodes for the site map.



 public class StoreDetailsDynamicNodeProvider
      : DynamicNodeProviderBase
    {
        WhoTracksMeEntities storeDB = new WhoTracksMeEntities();

        public override IEnumerable GetDynamicNodeCollection()
        {
            // Build value
            var returnValue = new List();

            // Create a node for each Cookie
            foreach (var ck in storeDB.cookies1.Where(x => x.DescriptionStatus.ToUpper() == "MODERATION"))
            {
                DynamicNode node = new DynamicNode();
                node.Title = ck.Name;
                node.Controller = "Cookie";
                node.Action = "CookieDetail";// +"/" + ck.Id;
                node.RouteValues.Add("id", ck.Id);

                returnValue.Add(node);
            }

            // Return
            return returnValue;
        }

        public override CacheDescription GetCacheDescription()
        {
            return new CacheDescription("StoreDetailsDynamicNodeProvider")
            {
                SlidingExpiration = TimeSpan.FromMinutes(1)
            };
        }


    }


Note that these should be registered in Web.config, i.e. under pages tag  in webconfig .add the following:



  In    namespaces
     
        namespace="MvcSiteMapProvider.Web.Html" ;