Jan 27, 2014

What is Purpose of Solution Explorer Right Click “Clean Solution”


When you want to remove bin folder all dll files in your application .

You can use clean solution  in your Application and see in your bin file folder all dll files is removed.after you can use Rebuild the Solution now u can see in your bin folder now created the all new dll files is created.

Purpose :If you have any unblock the dll files or something else You got some error in build the solution now you can use the same.
 


Jan 21, 2014

Attribute Routing in asp.net MVC 5


o   MVC5 support a new type of routing it’s called an attribute routing.
o   As the Name implies routing uses attribute to define routes.
o   The earlier style of routing its called Convention based routing.
o   Still implement attribute routing fully supported routing.
o   You can combine convention based routing and attribute routing in same project is possible.


Why we can use Attribute Routing?
The previous version of asp.net MVC using RouteConfig.cs file point Actual controller.

public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }
            );
        }
    }


When the route definitions are co-located with the action. Within the same source file rather than begin declared on an external configuration class.

How to use Attribute Routing:

It can be used routing call MapMVCAttributeRoutes during configuration.

public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapMVCAttributeRoutes();
        }
    }

Both using convention based routing and Attribute routing.


public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapMVCAttributeRoutes();
routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }
            );

        }
    }

Sample Syntax Attribute Routing:

       public class TestController : Controller
        {
            [Route("Test/(TitleID?)")]
            public ActionResult View(long TitleID)
            {
                return View();
            }
         }



















Jan 20, 2014

Different between TempData vs. ViewData vs. ViewBag

 

TempData


  • TempData is a Dictionary Object
  • It can be used assign value and return

public abstract class ControllerBase : Icontroller
{
public TempDataDictionary TempData { get; set; }
}

  • View is fully loaded it can be used.
  • It’s required typecasting for complex data type and check for null values to avoid error.
  • It is used to store only one time messages like error messages and validation messages
  • TempData is available MVC2,MVC3,MVC4

Syntax:


TempData["cust"] = “Saved SuccessFully”;





ViewData

  • ViewData is a Dictionary object
  • It can be used assign value and return

public abstract class ControllerBase : Icontroller
{
public ViewDataDictionary ViewData { get; set; }
}

o       View Data is used to pass data from controller to corresponding view.
o       It’s life lies only during the current request.
o       If redirection occurs then it’s value becomes null.
o       It’s required typecasting for complex data type and check for null values to avoid error.
o       ViewData is available MVC2,MVC3,MVC4

Syntax:

ViewData["cust"] = cust;


ViewBag *best
o       ViewBag is a dynamic property
o       It can be used return the value.
public dynamic ViewBag { get; }
o       If redirection occurs then it’s value becomes null
o       Wrapper around the ViewData and also used to pass data from controller to      corresponding view.
o       It doesn’t required typecasting for complex data type
o       ViewBag is available MVC4

Syntax:
ViewBag.Title = "Test Application";
ViewBag.Customer = “Test Manufacturing”;

Custom using add Title and customer



Recent Posts
Popular Articles

 

© 2013 MUNISH ORACLE DBA& .Net Developer. All rights resevered. Designed by Templateism

Back To Top