background preloader

NuGet Gallery

NuGet Gallery

ASP.NET MVC Partial Views and Strongly Typed Custom ViewModels I'm in the process of rewriting mikesdotnetting.com using the ASP.NET MVC framework. It's an interesting experience, in that this is my first exposure to MVC. The first stumbling block I encountered was how to pass data in a satisfactory way to Partial Views which only represent part of the data that is to be displayed in the View. Since I struggled to find clear guidance on this, I thought I would share a way to do it. There are a fair number of articles and blog pieces about the difference between ViewDataDictionery and ViewDataDictionery<TModel>, but there's no harm in taking the opportunity to recap - especially as the MSDN documentation is (at the moment) pretty thin on notes in the MVC Reference section. The first type of ViewDataDictionery is an untyped collection consisting of a string and an object. I am using the Entity Framework to generate the business objects and manage Data Access within the application. I don't want to use this class for the listing of Article Titles.

How to create lightweight reusable source code with NuGet Sometimes, you just have a reusable helper that you bring in to every project (i.e. an argument validation thingy, or the static reflection stuff, useful extension methods, and so on). You don’t always need them all, they are generally single-file utilities, and having a Common.dll looks overkill or dumb. Loose source file sharing has always been problematic, though: no packaging and versioning mechanism (unlike an assembly), hard to integrate with source control systems (SVN has external repository mappings, but nothing like that exists in TFS or Mercurial, AFAIK), and so on. I tried source files reuse before, with somewhat poor results. In a recent project I wanted to reuse (again) that darn useful Guard.cs file. Two key technologies enable some pretty cool and robust source file reuse nowadays: NuGet: unless you’ve been living under a rock, you probably heard all the bignamestalking about it. So let’s get started and create the Guard package Creating the reusable source file And typing:

System.Xml Namespace () The System.Xml namespace provides standards-based support for processing XML. Supported standards Related namespaces The .NET Framework also provides other namespaces for XML-related operations. Processing XML asynchronously Differences from the W3C specs In two cases that involve constraints on model group schema components, the System.Xml namespace differs from the W3C recommendations. Consistency in element declarations: In some cases, when substitution groups are used, the System.Xml implementation does not satisfy the "Schema Component Constraint: Element Declarations Consistent," which is described in the Constraints on Model Group Schema Components section of the W3C spec. For example, the following schema includes elements that have the same name but different types in the same content model, and substitution groups are used. In this schema, type t3 contains a sequence of elements. Unique particle attribution: <e3><e2>1</e2><e2>2</e2></e3> becomes this: Security considerations Reference

How to: Deploy an ASP.NET MVC Application If your hosting provider already has ASP.NET MVC 1.0 installed on the hosting server, deploying your MVC application is no different that deploying any ASP.NET Web application. However, if the hosting provider does not currently support ASP.NET MVC 1.0, you must upload the required MVC assemblies in the Bin folder of your deployed application. After ASP.NET MVC is installed, the following assemblies are located in the global assembly cache (GAC) on your computer: System.Web.Mvc (the ASP.NET MVC assembly) System.Web.Routing (a .NET Framework assembly that is required by ASP.NET MVC) System.Web.Abstractions (a .NET Framework assembly that is required by ASP.NET MVC) If your hosting provider has ASP.NET version 3.5 Server Pack 1 installed, you have to upload only the System.Web.Mvc assembly. ASP.NET MVC runs in medium trust. To deploy an ASP.NET MVC application In Visual Studio, open the project that you want to deploy.

NuGet XML Processing The Extensible Markup Language (XML) is a markup language much like HTML or SGML. This is recommended by the World Wide Web Consortium and available as an open standard. The System.Xml namespace in the .Net Framework contains classes for processing XML documents. Following are some of the commonly used classes in the System.Xml namespace. XML Parser APIs The two most basic and broadly used APIs to XML data are the SAX and DOM interfaces. Simple API for XML (SAX) : Here, you register callbacks for events of interest and then let the parser proceed through the document. SAX obviously can't process information as fast as DOM can when working with large files. SAX is read-only, while DOM allows changes to the XML file. For all our XML code examples, let's use a simple XML file movies.xml as an input: <? Parsing XML with SAX API In SAX model, you use the XmlReader and XmlWriter classes to work with the XML data. Example 1 This example demonstrates reading XML data from the file movies.xml. Example 2

Sorting, Filtering, and Paging with the Entity Framework in an ASP.NET MVC Application (3 of 10) The Contoso University sample web application demonstrates how to create ASP.NET MVC 5 applications using the Entity Framework 6 Code First and Visual Studio 2013. For information about the tutorial series, see the first tutorial in the series. In the previous tutorial you implemented a set of web pages for basic CRUD operations for Student entities. The following illustration shows what the page will look like when you're done. Add Column Sort Links to the Students Index Page To add sorting to the Student Index page, you'll change the Index method of the Student controller and add code to the Student Index view. Add Sorting Functionality to the Index Method In Controllers\StudentController.cs, replace the Index method with the following code: This code receives a sortOrder parameter from the query string in the URL. The first time the Index page is requested, there's no query string. ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? These are ternary statements. Build the project.

Squirrel - The Programming Language Filtering a Grid of Data in ASP.NET MVC By Scott Mitchell Introduction This article is the fourth installment in an ongoing series on displaying a grid of data in an ASP.NET MVC application. The previous two articles in this series - Sorting a Grid of Data in ASP.NET MVC and Displaying a Paged Grid of Data in ASP.NET MVC - showed how to sort and page data in a grid. In particular, the demo we examine in this installment presents an interface with three filtering criteria: the category, minimum price, and whether to omit discontinued products. Like with its predecessors, this article offers step-by-step instructions and includes a complete, working demo available for download at the end of the article. Step 0: A Brief Roadmap This article walks through displaying a filtering interface and then showing only those matching records in a grid of data. Recall that in Sorting a Grid of Data in ASP.NET MVC the demo was available at the URL www.yoursite.com/Products/Sortable. categoryId - an integer value. Step 3: Creating the View

Build a Coded UI Test without a UI Map - InCycle Software So I ran into a customer recently that was getting pretty advanced with Coded UI and they were having trouble maintaining the UI Map technology as part of Visual Studio. One the things that I had noticed is that the UI Map does store lots of information including page names, URL's and many other things that are interesting but not needed. This technology is great for beginners that need to get started with the technology. So as I started thinking about it I was reflecting on some of the technologies that I have used before that included a way to search the DOM or Control Tree if you did not have an items mapped. As I found quickly there are many ways solve this problem including taking the generated code from UI Map and move it around. As I started to think about how to condense the code and quickly .Net Generics came to mind. Hope this helps someone else solve a very common problem.

Using DbContext in EF 4.1 Part 4: Add/Attach and Entity States - ADO.NET Blog The information in this post is out of date. Visit msdn.com/data/ef for the latest information on current and past releases of EF. For Add/Attach and Entity States see Version 4.1 of the Entity Framework contains both the Code First approach and the new DbContext API. The posts in this series do not contain complete walkthroughs. An entity can be in one of five states as defined by the EntityState enumeration. SaveChanges does different things for entities in different states: Unchanged entities are not touched by SaveChanges. The following examples show ways in which the state of an entity or an entity graph can be changed. A new entity can be added to the context by calling the Add method on DbSet. using (var context = new UnicornsContext()) { var unicorn = new Unicorn { Name = "Franky", PrincessId = 1}; context.Unicorns.Add(unicorn); context.SaveChanges(); } Another way to add a new entity to the context is to change its state to Added.

Code Smart Not Hard - CodedUITests In one of my previous posts, I talked about Setting up a Build Server to run Coded UI Tests. In this post I am going to talk about creating a Coded UI Test and running it from Microsoft Test Manager. This completes the full testing story. The build server can run the regression tests and the tests can run any automated test from Microsoft Test Manager on demand. Create Test Case First, create the Test Case in Microsoft Test Manager. Next, in MTM, go to the Test Tab and Run the test. Finish going through the test. Switch your hat to the Developer cap. Since we already have the action recording, choose the “Use an existing action recording.” Once you verify the test is passing in Visual Studio, you can associate the automated test back to the test case. Find the Test Case and choose Ok. Also the Automation Status has been changed to Automated. Creating the Test Environment Now that we have the test case automated, we need to configure the test environment before we can run it. Test Server 1.

Related: