Deploying rdlc report on IIS inside asp.net web application

Hi,

I had a new problem recently about deploying the rdlc reports on IIS server. The problem was, when I publish the application, report inside the “Reports” folder was not copied

When I included my .rdlc files they would not output during a publish as well.

To solve this click on the file, go to the properties

Under ‘Build Action’ my project had the setting of ‘Embedded Resource’.

Changing this setting to ‘Content’ fixed this issue for me.

Also Set Copy to Output Directory – Do not copy

 

And you are done.

 

🙂

Upgrade Application from Asp.Net MVC2 to MVC3

Upgrade Application from Asp.Net MVC2 to MVC3

It’s been a much long after MVC3 is been released & now it is much stable. So while working on a project, I need to upgrade my ASP.Net MVC 2 project to MVC 3.

ASP.Net MVC 3 can be installed side by side ASP.Net MVC 2 on you PC, which gives you flexibility in choosing when to upgrade an MVC2 application to MVC3. It is been very easy to upgrade the project to MVC3. We just need to follow following steps

  • Remove all references of System.Web.Mvc from each project in solution.
  • Now add a reference for System.Web.Mvc 3.0 to each of the project in the solution.
  • Also add a reference of System.Web.Helpers 2.0 to web project.
  • Also add a reference of System.Web.WebPages 2.0 to web project.
  • Go to views folder & open the Web.Config file & replace Version = 2.0.0.0 with version 3.0.0.0
  • Also add following code  to this Web.Config

  • Open the root Web.Config file & replace all references of “System.Web.Mvc 2.0.0.0” with “System.Web.Mvc 3.0.0.0”.
  • Now in appSettings add following keys

  • Now we need to make sure our system.web->pages->namespaces tag contains following entries

  • In the system.web->compilation->assemblies we should have following entries

  • Finally under the configuration -> runtime section put following code

  • And lastly add following javascript on your master pages, you need to add this javascript file to Scripts folder.  We need to get this file from any asp.net mvc3 project & paste it in the scripts folder. Also it is recommended you replace the old javascript files such as MicrosoftAjax.js, MicrosoftMvcAjax.js & MicrosoftMvcValidation.js.

Yuhu……………! Here we are. Now just compile & run your code. Now it will run on MVC3. Also we need to make sure we are targeting .net Framework 4.0 while upgrading the MVC2 application to MVC3.

Also there is a tool available to upgrade the MVC2 to MVC3. Here is a link to the tool

http://weblogs.asp.net/leftslipper/archive/2010/07/28/migrating-asp-net-mvc-2-applications-to-asp-net-mvc-3-preview-1.aspx

Cheers…..!

You can find the source code here.

Why not to use ViewData, ViewBag or TempData !

There are various ways of passing data from Controller to View or vice versa. For example when passing some values to View we can use ViewData Or TempData Or ViewBag. We set the appropriate values for keys in one of these & we can access it on view where ever we need it. This approach is used very extensively in some books as well as many of the blog posts. Though it is very easy & handy to set the values in ViewData, it has some pitfalls.

Before, we will see how we can pass the values from Controller to ViewData. Consider following simple example which contains a drop down list & a date time which we need to display on View. For that purpose controller would look something like this

[HandleError]

public class HomeController : Controller

{

private ICountryRepository _countryRepository { get; set; }

public HomeController(ICountryRepository CountryRepository)

{

_countryRepository = CountryRepository;

}

public ActionResult Index()

{

ViewData[“Country”] = _countryRepository.GetCountryList();

ViewData[“CurrentDate”] = DateTime.Now;

return View();

}

}

Here in Home controller we are setting the values for 2 entities one is Country & other is CurrentDate. Country is a drop down list whereas CurrentDate will display the current date time. The GetCountryList() function here returns IEnumerable.

The view for above will be like this

<%@ Page Language=”C#” MasterPageFile=”~/Views/Shared/Site.Master” Inherits=”System.Web.Mvc.ViewPage” %>

<asp:Content ID=”Content1″ ContentPlaceHolderID=”TitleContent” runat=”server”>

Home Page

</asp:Content>

<asp:Content ID=”Content2″ ContentPlaceHolderID=”MainContent” runat=”server”>

Country : <%: Html.DropDownList(“Country”, ViewData[“Country”] as SelectList) %>

Current DateTime : <%: ViewData[“CurrentDate”]%>

</asp:Content>

Though this looks pretty simple, however we are doing a lot of hardcoded string passing which is not at all good. The main pain with passing hardcoded strings is they can never be cause on compile time. Passing hardcoded string is not a big problem, we can solve it by using string Constants. But ideally, string hardcode should be avoided in order to avoid future mess which may occur during the maintenance phase of the project. Also we need to consider situations where we may need to show more than 10 items on the view, are we going to keep all these items to ViewData ? Also, see how we need to cast ViewData[“Country”]  to SelectList in order to pass it to the DropDownList helper function. While using ViewData all across the application, we need to take this pain.

Though this post was all about not using ViewData, ViewBag or TempData, there are situations where we need to use these as we cannot use View Models there. We will discuss these things in later posts.

Hello world!

After only thinking to start technical blog for last 2 years finally I will be starting to do some technical blogging.

The technical blogging I will do will involve, contents related to Microsoft Technologies such as ASP.Net, ASP.Net MVC, Entity Framework, LINQ, AJAX, Telerik ASP.Net MVC Controls, & other Microsoft Technologies.

So Happy reading to you & Happy blogging to me ……. 😉