Friday, December 11, 2015

The computer restarted unexpectedly or encountered an unexpected error. windows installtion can not proceed to install windows click ok to restart the computer and then restart the installation

1)      On the same error screen press SHIFT+F10 and it will open up a black Window. (a command prompt window)
2)       In  the black windows type the word "regedit"(without the inverted commas and hit enter. That will open the registry editor.
        In the Registry Editor..
                Browse to....
        HKLocal machine/SYSTEM/SETUP/STATUS/ChildCompletion, and after highliting childcompletion,on the right hand side check for setup.exe. if the value is 1 change it to 3.(by double clicking on setup.exe and changing the value shown in the box).
Then close the registry editor and then also close the black window.
      Then click on OK for the error and the computer will restart and the installation may complete.  just try it and let me know if it worked.

Wednesday, December 9, 2015

How to Read Rout optional parameter in null parameter Action Method in a Controller in MVC ?

By default, the values for action method parameters are retrieved from the request's data collection. The data collection includes name/values pairs for form data, query string values, and cookie values.
The controller class locates the action method and determines any parameter values for the action method, based on the RouteDatainstance and based on the form data. If the parameter value cannot be parsed, and if the type of the parameter is a reference type or a nullable value type, null is passed as the parameter value. Otherwise, an exception is thrown.
There are several ways to access URL parameter values in the action methods of controller classes. The Controller class exposesRequest and Response properties that can be accessed in an action method. These properties have the same semantics as theHttpRequest and HttpResponse objects that are already a part of ASP.NET. However, the Request and Response objects of theController class accept objects that implement the HttpRequestBase and HttpResponseBase abstract classes instead of being sealed classes. These base classes make it easy to create mock objects, which in turn makes it easy to create unit tests for controller classes.
The following example shows how to use the Request object to retrieve a query-string value named id.
public void Detail()
{
    int id = Convert.ToInt32(Request["id"]);
}

Marking Public Methods as Non-Action Methods

By default, the MVC framework treats all public methods of a controller class as action methods. If your controller class contains a public method and you do not want it to be an action method, you must mark that method with the NonActionAttribute attribute.
The following example shows a method that is marked with the NonAction attribute.
[NonAction]
private void DoSomething()
{
    // Method logic.
}

Thursday, December 3, 2015

Differences between Html.TextboxFor and Html.EditorFor in MVC and Razor ?

TextBoxFor: It will render like text input html element corresponding to specified expression. In simple word it will always render like an input textbox irrespective datatype of the property which is getting bind with the control.
EditorFor: This control is bit smart. It renders HTML markup based on the datatype of the property. E.g. suppose there is a boolean property in model. To render this property in the view as a checkbox either we can use CheckBoxFor or EditorFor. Both will be generate the same markup.

What is the advantage of using EditorFor?

As we know, depending on the datatype of the property it generates the html markup. So suppose tomorrow if we change the datatype of property in the model, no need to change anything in the view. EditorFor control will change the html markup automatically.

How to call ASP.NET WEB API from .Net Framework 2.0

In Vb.Net

 Public Function ReadAllData() As EmployeeEntityCollection
            Dim employee As EmployeeEntityCollection

   Using client As New WebClient()
        Dim _baseAddress As String =       System.Configuration.ConfigurationManager.AppSettings("ClientbaseAddress")                     
                client.Headers(HttpRequestHeader.Accept) = "application/json"
       client.BaseAddress = _baseAddress
       Dim ApiUrl As String = "Employee/ReadAllData/?EmployeeId=" + String.Empty + "&EmployeeName=" + String.Empty

employee= JsonConvert.DeserializeObject(Of  EmployeeEntityCollection)(client.DownloadString(ApiUrl))

           Return employee

   End Using

  End Function

In C#.Net


public EmployeeEntityCollection ReadAllData() 
{
       EmployeeEntityCollection employee;
   
   
      using (var client = new WebClient())
         {
 string _baseAddress=
System.Configuration.ConfigurationManager.AppSettings["ClientbaseAddress"];
    client.Headers[HttpRequestHeader.Accept] = "application/json";
client.BaseAddress = _baseAddress;
string ApiUrl = "Employee/ReadAllData/?EmployeeId=" + string.Empty + "&EmployeeName=" + string.Empty;

employee = JsonConvert.DeserializeObject<EmployeeEntityCollection>(client.DownloadString(ApiUrl));

    return employee

         }

}