ASP.NET MVC IIS problem - asp.net-mvc

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?

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.

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>

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

Related

How can I reference a script that is in my pages directory?

I'm trying to keep a good practice of keeping context together and in that regard, I like how Razor Pages forces you to place your view models next to its view. I'd like to do this with script files as well.
For example, if script is a bit large and is only used on this particular page, it may not be the cleanest thing to have it in a render section in the cshtml. Instead, I'd want to place it into its own .js file. But to keep the project easy to navigate for team members, I'd like to place that .js file in the same folder next to its view and view model. I'm not sure how to link that file, or if I even can. If I give src a path to the file, it is not found. Assuming that's because wwwroot is the only folder setup to host static files.
Suggestions?
You can add an option to the StaticFilesProvider in your Configure method:
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(),"Pages")), RequestPath="/Pages"
});
See the documentation on Static Files in ASP.NET Core: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-2.1

Using Strongly Typed models in Umbraco 7.6.9?

I have tried looking into using Strongly Typed models (setting Umbraco.ModelsBuilder.ModelsMode to either AppData or Dll) for a while now, and I never fully understood how it works.
I already changed the Umbraco.ModelsBuilder.ModelsMode value and I generated the models inside the backoffice ModelsBuilder, then I included the App_Data\Models into Visual Studio, but what then?
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Home>
#using Our.Umbraco.Vorto.Models;
#using Our.Umbraco.Vorto.Extensions;
#using ContentModels = Umbraco.Web.PublishedContentModels;
This is the code for my Home view. No matter what I try, I cannot access the #Model.PROPERTY or #CurrentPage.PROPERTY from my content. I can see the different properties inside my MODEL.generated.cs files.
What steps do I need to take, in order to do things like #Model.PROPERTY?
Okay, so it seems like there has been some changes in the newest 7.6.9 release (or maybe 7.6.8). This is what I had to do now:
<add key="Umbraco.ModelsBuilder.Enable" value="true" />
<add key="Umbraco.ModelsBuilder.ModelsMode" value="Dll" />
Then I can go into the backoffice and generate the models. The models are included into the project (location: ~\App_Data\Models\). Umbraco.Web.PublishedContentModels.dll from the ~\bin\ folder has to be included as well.
Then, because of .NET Core I think, I got an error when I tried loading my application saying this:
More than one type want to be a modle for content type File
This was caused because I had included everything inside ~\bin\, which means I had also included my Project.dll, Project.dll.config, and Project.pdb files. The Project.dll file also includes the same models, apparently, so I had to exclude those 3 files.
Now it simply works and I can now do #Model.Content.PROPERTY flawlessly.
You're not talking about "Dynamic" models, but Strongly Typed Models generated by Models Builder. By default Umbraco ships with PureLive setting which is keeping models in memory and generates them on the fly. It can be considered as "dynamic".
The tool and it's behaviour is well documented here: https://github.com/zpqrtbnk/Zbu.ModelsBuilder/wiki
Regarding modes of it, you can find all about it exactly in this place: https://github.com/zpqrtbnk/Zbu.ModelsBuilder/wiki/Builder-Modes
But answering your question - after you've changed the configuration, you need to compile your application as you need to keep those classes inside the DLL with which you're shipping your website. You're also able to regenerate models straight from your Developer's dashboard in Umbraco Backoffice.
You need to remember that if you would like to use DLL, LiveDLL or PureLive configuration - you need to get rid of classes generated inside your AppData or any other directory used with this mode as you'll experience errors saying about 'More that one type want to be a model for content type File'.
After that you should be able to access all properties of the document type via Model.Content.PropertyAlias. You probably missed the Content object, which is the strongly typed, IPublishedContent representation of you document.
Hope it will help you to make it work :)

TYPO3 Filelist: In which way I can set the title / description instead of the filename at TYPO3 7.6.2?

I have a problem using the filelist / upload element of TYPO3 at the current new version 7.6.2. I want to use the title or description part instead of the filename while rendering the list.
I found lots of information on that and in TYPO3 version 6.x it worked with:
tt_content.uploads.20.renderObj = COA
tt_content.uploads.20.renderObj.20.1.data = file:current:title
tt_content.uploads.20.renderObj.30 >
When I insert this lines into the TS of the page where I want to use the filelist it does not work with the new css_styled_content for 7.x.
When I include "CSS Styled Content TYPO3 v6.2 (css_styled_content)" to the setup of the template, the filelist works (but other parts of page not).
Therefore the question: Do you know if there are some changes in rendering the filelist at 7.x?
Thanks for your help
Markus
The reason why you can't change the name => title anymore is that you included Fluid Styled Content ext which is required i.e. for rendering the Text & Media CEtype. It massively overrides the CSS styled content and replaces (almost) whole TS declarations with Fluid templates/layouts/partials from typo3/sysext/fluid_styled_content/Resources/Private folder. I.e.: in typo3/sysext/fluid_styled_content/Resources/Private/Templates/Uploads.html:29 there is {file.name} used which should be more advanced condition...
To change it:
Copy all folders from typo3/sysext/fluid_styled_content/Resources/Private to your custom destination i.e.: fileadmin/fluid_styled_content/Private (this is for avoiding loosing of your changes after system upgrade.
It can be any other path, for an instance you can create your custom ext and put it into typo3conf/ext/yourext/Resources/Private/...
Go to your TypoScript template > Constant Editor > Category: Content and set new paths in these fields:
Path of Fluid Templates... - fileadmin/fluid_styled_content/Private/Templates
Path of Fluid Partials... - fileadmin/fluid_styled_content/Private/Partials
Path of Fluid Layouts... - fileadmin/fluid_styled_content/Private/Layouts
After that go to fileadmin/fluid_styled_content/Private/Templates/Uploads.html:29 and replace the code:
{file.name}
with:
<f:if condition="{file.title}"><f:then>{file.title}</f:then><f:else>{file.name}</f:else></f:if>
As you can see this way you can also change other CEtypes and their typical settings (i.e. add the responsive classes if working with RWD).
On the other hand take a look there are some drawbacks of this solution, i.e. default layouts repeats the <div id="c123">... which is invalid :/
P.S.:
Also just realized that Fluid Styled Content doesn't handle other things, i.e. different layouts for Uploads (that the first thing I saw, didn't check other CEtypes) so you need to consider yourself if it is OK for your project at the moment. I prefer to stay with old way (no need for Text & Media CE) and disable FSC now (I'm pretty sure, that soon it will be nice alternative for CSC, but not now imho :/) To revert typical state you can use these lines mentioned in the GitHub here within your PageTS.

overriding front template translations doesn't work

I'm working on prestashop and I'm Trying to override "order detail page" in front (customer's details orders).
This is how I did :
I copied file \controllers\front\OrderDetailController.php into folder \override\controllers\front\OrderDetailController.php
I copied also default template file order-detail.tpl into folder override/customtemplate/order-detail.tpl
And In OrderDetailController.php I have specified template directory like that
$this->setTemplate(_PS_OVERRIDE_DIR_ . '/themes/parfum_evo/order-detail.tpl');
I tried, it works fine except translations. Even watching the documentation, no test solution seems to work.
Could anyone help me? Thank you in advance :'(
The php override sits in the correct place. As for the other, you specified the path the override/customtemplate/order-detail.tpl but then placed it in override/themes/parfum_evo/order-detail.tpl. I take it as customtemplate is farfum_evo really, but you need to add another one named themes, after override, using that structure. I think. Because there is a hook named
DisplayOverrideTemplate
Which should take care of this, while I believe setTemplate for controllers will always grab from the main theme folder

ASP.NET MVC locating cs files generated from cshtml?

So I've recently started with ASP.NET MVC 4. I'm using the razor engine.
My question is concerning the view files, with suffix cshtml. It seems to me that these are precompiled into *.cs files by razor which in turn are then compiled into MSIL. (A pattern that is familiar from my days as a JSP developer.) One reason why I am making this assumption is that if I enter some invalid c# code into the cshtml file I get a compilation error displayed like this:
Line 34: public class _Page_Views_BaseDataAdmin_Index_cshtml : ...
And line 34 is not indicative of where the error is in the cshtml file, just as the class _Page_Views_BaseDataAdmin_Index_cshtml seems to refer to a regular .net class not the view file.
So my question is: Where do I find the cs file? Specifically, in the example above, "_Page_Views_BaseDataAdmin_Index_cshtml.cs"? Maybe I need to add some config to tell MVC to keep this .cs file on disk, if so, how do I do this?
Thanks!
A quick tip to find the generated files is to add this to your .cshtml file.
This will show you immediately the full path
<div>This file is compiled to #this.GetType().Assembly.CodeBase</div>
You can find the compiled views in your Temporary ASP.NET Files folder.
First find the .compiled file that corresponds to your view (ex: home.cshtml):
home.cshtml.a8d08dba.compiled
This file contains the assembly name: assembly="App_Web_hkc53urb"
Your .cs file will be the assembly name concatenated with a number: App_Web_hkc53urb.1.cs
An easier approach might be to use Windows search for your view name in the temp ASP.NET directory.

Resources