Posted tagged ‘ASP.NET MVC’

Updating ASP.NET MVC Nuget Packages

September 2, 2012

Here is an error and solution I got today when updating Nuget packages for ASP.NET MVC.

Error:

‘System.Web.Optimization.BundleCollection’ does not contain a definition for ‘RegisterTemplateBundles’ and no extension method ‘RegisterTemplateBundles’ accepting a first argument of type ‘System.Web.Optimization.BundleCollection’ could be found (are you missing a using directive or an assembly reference?) …\Global.asax.cs 87 24 FlixPicks.Net

Solution:

In Global.asax -> Application_Start

Change:

BundleTable.Bundles.RegisterTemplateBundles();

To:

BundleMobileConfig.RegisterBundles(BundleTable.Bundles);

ASP.NET MVC RenderPartial is replacing the entire page

May 17, 2009

I ran into an issue using RenderPartial that was in the end simple to solve but took a bit of time to figure out.

Situation

You have your let’s call it the “parent view” that has the Ajax.BeginForm on it as well as the div where you are rendering the partial view by using Html.RenderPartial.  When you load the page you see all of the content of your master page, the “parent view”, as well as the partial view.  Fantastic.  Now you submit the form by clicking a button or however you are doing it so that the partial view controller method is called.  This controller method is returning something like PartialView(“PartialViewName”, viewData);.  All seems to be working great, and then the browser ends up only displaying the contents of the partial view.  Hey, what happened to the master page and the “parent view” content.

As I understand it, the Ajax.BeginForm works is by calling java script functions in MicrosoftAjax.js and/or MicrosoftAjaxMVC.js.  I say and/or because I know that you need them both, however, I did not dig into how it all works nor do I really care. ( That is until the next problem 🙂 )

Solution

In the end the solution is simple.  Just make sure that you reference the proper java script files.  I ended up putting them in my master page as follows:

<head runat="server">
    <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
    <title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
    <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
</head>

Hope that saves you some hair!
Tom