Webistrate - Draw Your Own Conclusions

ASP.NET: Entity Framework’s Code-First with an ObjectContext

Posted by Jamie Munro | April 30, 2012 | Tags: , , ,

If the following blog interests you, it’s probably because you’re using Entity Framework with a Code-First approach and whatever it is you are trying to do *must* use an ObjectContext instead of the standard DbContext.  I’m sure, like me, you thought this shouldn’t be too hard.  Then you started hitting roadblocks like, Metadata is required in your connection string.  What’s metadata?  This is only needed in Database-First so you can tell the framework where your edmx and other definition files are, so why do I need this with Code-First, I don’t have these files?

This was definitely my first reaction as well.  So after much trial-and-error and research, I have the solution!

See the solution »

Share


MVC 3: Pass Model or Form Data through a Redirect

Posted by Jamie Munro | February 6, 2012 | Tags:

Have you ever wanted to pass form data or perhaps even a full model from one action to another through a RedirectToAction?  By adding a new library package from NuGet, this can be accomplished with a few small changes to your controllers.

See the solution »

Share


MVC 3: Compile Views During Project Build

Posted by Jamie Munro | January 9, 2012 | Tags:

Most ASP.NET developers will use Visual Studio to build their projects. The program has evolved quite a bit over the past few years.  Including excellent features like Intellisense inside of ASP.NET MVC view files as well as some error detection in these, by default, not compiled elements.  However, when ViewBag variables are used or other run-time specific elements, Visual Studio is unable to determine potential errors in these view files.  Have no fear though; there is a nice and simple solution to help solve this problem!

See the solution »

Share


MVC 3: Accessing the RouteData inside of your code

Posted by Jamie Munro | December 5, 2011 | Tags:

You want to perform some dynamic processing in your code and you need to determine either the name of the current controller or the current action or both.

See the solution »

Share


MVC 3: Posting form variables that are not strongly typed

Posted by Jamie Munro | November 28, 2011 | Tags:

In a lot of the MVC 3 examples that are available on the Internet today, they are quite typically strongly typed to a model, e.g.

[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
// code here
}
}

This is extremely useful for the validation abilities and many other aspects; however, there are times when some or all of the data is not strongly typed; then what do you do?

See the solution »

Share


MVC3: Using Class Extensions to simplify your code with the UrlHelper

Posted by Jamie Munro | September 15, 2011 | Tags:

When you have a website with a lot of static content: images, Javascript, CSS, etc… you will find yourself constantly typing out the same path information with the exception of the name of the actual file.  Creating a class extension to the UrlHelper can help greatly reduce your development efforts with a few simple additions.

See the solution »

Share


MVC3: Login System with the AuthorizeAttribute

Posted by Jamie Munro | August 23, 2011 | Tags:

If you are creating your first website with MVC3 and it requires users to register and login, the AuthorizeAttribute and a built-in Internet Application template will get you started.

See the solution »

Share


Buy one of my books