Accessing MVC’s model property from Javascript

var firstName = @Html.Raw(Json.Encode(Model.FirstName));

Source: https://stackoverflow.com/questions/16361364/accessing-mvcs-model-property-from-javascript

 

Advertisements

ITextSharp – PDF Creation Example

Document document = new Document(PageSize.A4, 0, 0, 50, 50);
System.IO.MemoryStream msReport = new System.IO.MemoryStream();


try {
    // creation of the different writers
    PdfWriter writer = PdfWriter.GetInstance(document, msReport);


    // we add some meta information to the document
    document.AddTitle("My Title");
    document.AddAuthor("Me");
    document.Open();


    for (int i = 1; i <= 5; i++)
    {
        document.NewPage();
        iTextSharp.text.Table datatable = new iTextSharp.text.Table(3);
        datatable.Padding = 2;
        datatable.Spacing = 0;
        float[] headerwidths = { 6, 20, 32 };
        datatable.Widths = headerwidths;
        datatable.DefaultHorizontalAlignment = Element.ALIGN_LEFT;
        datatable.AddCell(i.ToString());
        datatable.AddCell("This is my name.");
        datatable.AddCell("0123456789");


        datatable.AddCell("No");
        datatable.AddCell("Yes");
        datatable.AddCell("No");
     

        document.Add(datatable);
     }
}
catch (Exception e) {
    Console.Error.WriteLine(e.Message);
}


// we close the document 
document.Close();


Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=Export.pdf");
Response.ContentType = "application/pdf";
Response.BinaryWrite(msReport.ToArray());
Response.End();

 

Source: https://forums.asp.net/t/1428577.aspx?Add+a+new+page+in+iTextSharp

WHAT IS ODATA? ADVANTAGES AND DISADVANTAGES

OData is the Open Data Protocol. It is an open web protocol started by Microsoft to expose data using existing web technologies. This is based on Representational State Transfer (REST) full architecture. HTTP, AtomPub (similar to RSS, but specifically introduced special XML format for OData), JSON are all supported.
Here, the URL is the primary operator on the data query.

WCF OData Service

In Visual Studio 2013, there is a template to create a WCF OData service. So, we can easily create an OData Service using Visual Studio 2010.

Example of OData Service has been used

  1. Last (2010) football world cup (S.A), the scoring website was done using an OData Service.

Why should we use an OData Service? 

  1. OData is based on the REST architecture, so we can retrieve data based on an URL.
  2. It also supports HTTP, Atom Pub as well as JSON format.
  3. It has support for any type of data source. Even you can use a custom class as a data source.
  4. No need to create a proxy service object. So, it is lightweight to use.
  5. You can create your own custom methods and expose it.
  6. Since it is lightweight, the interaction between server and client is fast. Thus, performance is good.
  7. It offers full CRUD support by using the different HTTP methods:
    • GET: Gets one or many entries.
    • POST: Create a new entry.
    • PUT: Update an existing entry.
    • DELETE: Remove an entry.

 

  1. A WCF Data service can expose an entity model via an URI.
  2. A WCF Data service could be consumed by any type of client like Windows, SilverLight, Web, AJAX and console.

Limitations

  1. Since it is purely URL based, it is less secure.
  2. As per my observation, not every query operator in LINQ is available in OData like Filter, Skip, Take etc.

Where is it suitable to use it?

  1. The case in which performance is more important than security. For example, as I said before it was used in the 2010 Football World Cup scoreboard.

Working of a WCF Data Service

There are five components.

  1. DataBase.
  2. Data Access layer using ADO.Net Entity model or LINQ.
  3. Entity Model Implementing Iqueryable and Iupdatable Interface.
  4. WCF Data Service exposing CRUD Operations on entity model as REST Service.
  5. Consuming it on various types of clients.

Supported Message Format

  1. JSON
  2. XML (ATOM)

Source: https://sandippatilprogrammer.wordpress.com/2013/12/03/what-is-odata-advantages-and-disadvantages/

 

LINQ inner query example

//var innerQuery = from depts in this.DbContext.Departments where depts.DeptName == “IT” select depts.DeptId;
            var innerQuery = from depts in this.DbContext.Departments where depts.DeptName == “HR” select depts.DeptId;
            //SELECT* FROM DEPARTMENTS WHERE DEPTID = 1;
            var result = from emp in this.DbContext.Employees where innerQuery.Contains(emp.DeptId) select emp;
            //SELECT * FROM EMPLOYEES WHERE DEPTID IN (1)
            //return employees;
            return result.ToList();

Button type “button” vs. “submit”

type
The type of the button. Possible values are:

  • submit: The button submits the form data to the server. This is the default if the attribute is not specified, or if the attribute is dynamically changed to an empty or invalid value.
  • reset: The button resets all the controls to their initial values.
  • button: The button has no default behavior. It can have client-side scripts associated with the element’s events, which are triggered when the events occur.

 

https://stackoverflow.com/questions/7117639/input-type-submit-vs-button-tag-are-they-interchangeable

https://stackoverflow.com/questions/37736056/button-type-button-vs-submit

https://stackoverflow.com/questions/290215/difference-between-input-type-button-and-input-type-submit

 

 

debug web service project in same solution as web site project

In your solution file, click properties go to the Startup project node (if it is not already selected)

Next select Multiple startup projects. Select your website and your webservice and in the Action column make sure both of them have “Start” selected.

Now when you debug your website and put a break point in you webservice it should hit the break point.

Thats all i can think of for your problem. Hope it helps.

https://forums.asp.net/t/1428325.aspx?debug%20web%20service%20project%20in%20same%20solution%20as%20web%20site%20project%20