Posts

Showing posts from June, 2014

Array, Arraylist, Hashtable, DataDicitonary in C#

Difference between Hash table and Data Dictionary in C#     HashTable & Dictionary,Dictionary is generic whereas Hastable is not Generic. · We can add any type of object to HashTable ,but while reteriving we need to Cast it to the required Type.So it is not type safe.But to dictionary,while declaring itself we can specify the type of Key & Value ,so no need to cast while retreiving. HashTable Program: Hashtable ht = new Hashtable(); ht.Add(1,"One"); ht.Add(2,"Two"); ht.Add(3,"Three"); foreach (DictionaryEntry de in ht) { int Key = (int)de.Key; //Casting string value = de.Value.ToString(); //Casting Console.WriteLine( Key + " " + value); } Dictionary Example class DictionaryProgram { static void Main(string[] args) { Dictionary<int,string> dt = new Dictionary<int,string>(); dt.Add(1,"One"); dt.Add (2,"Two"); dt.Add (3,"Three"); foreach (KeyValuePair...

Interview Questions

Difference between GET and POST. Which one is more secure? GET and POST methods are used for the data transfer between the web pages. GET mainly used for small data which is not secure because in case of GET method, the data which we are passing will be visible in the url so we can't keep the secure data which will be visible in the url. There is also limited data which can be passed in case of GET method (max 255 character). POST is used for transferring the huge data between the pages where we can keep the secure data and can transfer it. In case of using the POST method, the data which is transferring between the pages will not be visible so it is more secure than the GET method. Also there is no limit for POST method to post the data to the next page. POST is more secure What are Razor engines? How is it diff from ASP Engines? A. RAZOR engine is the new concept in the MVC 3 which is mainly used to create the views in the MVC applications. It created the cshtml pages for...

Interview Questions in SQL

1. Get all employee details from the employee table Select * from M_Employees  2. Get length of NAME from employee table select len ( emp1 ) from M_Employees 3. Get Name from employee table after replacing 'a' with '$' select REPLACE ( emp1 , 'a' , '$' ) from M_Employees 4.   Write syntax to delete table employee    DROP table employee; 5. Get employee details from employee table who joined after January 31 st Select * from M_Employees where jdate > '01/31/2014'       6. Get TOP 2 salary from employee table      select top 2 salary from M_Employees order by salary Desc     7 .   3rd Highest Salary of Employee        Method 1:            select   distinct salary  from  M_Employees e1  where   3= ( select   count (distinct salary)     ...

post textboxes values to Controller from View in mvc4

Method 1:   Thru  JQUERY In view : <div >     <span>DateTime:</span>      <input id="txtdatetimepicker" type="text" /> </div> <div id="dvDescription">     <span>Description:</span>     @Html.TextArea("txtDescription") </div> <div id="ContentDiv" class="ContentDiv"> </div> <input type="submit" id="btnStatusAdd" class="addactivitySubmitButton"  name="Command" value="Save" /> In Jquery: <script src="~/Scripts/jquery-1.8.2.js">         $('#btnSave').live("click", function (e) {              var datetime = $('#txtdatetimepicker').val();              var des = $('#txtDescription').val();              var data = {                        ...

HTML Helpers in ASP.NET MVC

Built-In Html Helpers Standard Html Helpers HTML elements like as HTML text boxes, checkboxes are used.   HTML Element Example TextBox @Html.TextBoxFor(m=>m.Name)  Output:  <input id="Name" name="Name" type="text" value="Name-val" /> TextArea @Html.TextArea(m=>m.Address , 5, 15, new{}))  Output:  <textarea cols="15" id="Address" name=" Address " rows="5">Addressvalue</textarea> Password @Html.PasswordFor(m=>m.Password)  Output:  <input id="Password" name="Password" type="password"/> Hidden Field @Html.HiddenFor(m=>m.UserId)  Output:  <input id=" UserId" name=" UserId" type="hidden" value="UserId-val" /> CheckBox @Html.CheckBoxFor(m=>m.IsApproved)  Output:  <input id="Checkbox1" name="Checkbox1" type="checkbox" value=...

How to display Check Box or DropDownList in Webgrid

Image
In WebGrid grid.Columns( grid.Column("", header: null, format: @<text> @Html.ActionLink("Select", "Edit", new { id = item.BranchID })</text>), grid.Column("BranchCode", header: "Branch Code", style: "col-01"), grid.Column("BranchName", header: "Branch Name" + ITManagementSystem.Models.Helper.SortDirection(null, ref grid, "BranchName"), style: "col-02"), grid.Column("BranchAddress", header: "Branch Address", style: "col-04"), grid.Column("CompanyName", header: "Company Name", style: "col-02"), grid.Column("BranchContactNo", header: "Contact No", style: "col-01"), grid.Column("BranchContactPerson", header: "Contact Person", style: "col-01"), grid.Column(header:"Is Active?", format:@<text><input type="checkbox"/>...

How to retain the data annotations or class during modify a table in the database

Image
In database-first approach since there is an existing database., The entity classes are automatically created by edmx model.: If we use [MetadataType(typeof(ConceptMetadataSource))] to attach a MetadataSource file which contains all the data annotations like [HiddenInput(DisplayValue = false)] or [Display(Name = "Title")]. The data annotations will be wiped out each time the entity classes are regenerated as the code will be regenerated once we modify a table in the database Solution: All you have to do is create another partial class and use Metadatatype attribute Create a metadata class in models as below…   Create a Partial class for the metadata in models as below… The new partial class can be created in a different folder

Handle Error in MVC

Add customer errors in webconfig Under < system.web > Add < customErrors mode = " On " >            </ customErrors > 2.    In View Under Shared Folder Add @{     Layout = null ; } <! DOCTYPE html > < html > < head >     < meta name ="viewport" content ="width=device-width" />     < title > Error </ title > </ head > < body >     < h2 >         Sorry, an error occurred while processing your request. Please Contact Admin     </ h2 > </ body > </ html > Error Handling Page for HTTP Status Code404 In Controller     Add new Controller as Error Controller Add then add public ActionResult NotFound()        {  ...