gigi
gigi

Reputation: 3956

ASP.NET MVC IIS problem

I have this piece of code in a .cs file in an ASP.NET MVC application:

HtmlTableCell r2c1 = new HtmlTableCell();
r2.Cells.Add(r2c1);
r2c1.ColSpan = 2;
r2c1.Style.Add("font", "1px arial");
r2c1.Style.Add("height", "10px");
r2c1.Style.Add("background-image", "url(/Content/Images/pagebgbottomwhite.jpg)");
r2c1.Style.Add("background-repeat", "repeat-x");

This works OK locally, but when I deploy my app using IIS 5 I don't see that picture.

How can I change that format of the URL so I can see it?

Upvotes: 0

Views: 197

Answers (3)

Anton Gogolev
Anton Gogolev

Reputation: 115877

First off, you don't really want to have this kind of code in your presenter.

As for URL format, try Server.MapPath("~/Content/Images/pagebgbottomwhite.jpg");. And ensure that this file is indeed where it should be.

Upvotes: 1

dove
dove

Reputation: 20692

Confirm that this file (/Content/Images/pagebgbottomwhite.jpg) is deployed. Is it set not to copy or was it left behind in deployment.

Upvotes: 0

tvanfosson
tvanfosson

Reputation: 532725

You really ought to be using CSS and defining a class that has these attributes. The url would then be relative to the location of the CSS file in the site: url(../Images/pagebgbottomwhite.jpg) -- assuming that your css file is in a sibling directory to Images. Then you would apply the CSS class to your element.

I also agree with Anton that, using MVC, this code should not be in your controllers/models, but rather in the view -- in which case you would not be using HtmlTableCell. In that case, and using pure CSS, it's simply a matter of creating the proper row in the table.

  <tr><td class="bottom-row" colspan="2"></td></tr>

Upvotes: 0

Related Questions