razor

ASP MVC: Upload Image from Database as Full Background CSS

旧时模样 提交于 2020-05-16 04:10:35
问题 I'm still fiddling with MVC and I want to set a full background image which would be retrieved from the database . This is what I used to do in CSS and love to do whenever I need full background: .banana3-sm{ background-image: url('../images/banana3-sm.png'); background-size: contain; background-position: center center; background-repeat: no-repeat; height: 100%; } Below is what I'm using currently because I don't know how to upload the image link from database to CSS. In Controller: model

ASP MVC: Upload Image from Database as Full Background CSS

一个人想着一个人 提交于 2020-05-16 04:10:11
问题 I'm still fiddling with MVC and I want to set a full background image which would be retrieved from the database . This is what I used to do in CSS and love to do whenever I need full background: .banana3-sm{ background-image: url('../images/banana3-sm.png'); background-size: contain; background-position: center center; background-repeat: no-repeat; height: 100%; } Below is what I'm using currently because I don't know how to upload the image link from database to CSS. In Controller: model

Declare global Razor Page variables in ASP.NET MVC [NOT Static]

谁都会走 提交于 2020-05-15 03:56:05
问题 I have a ConfigurationService class that is injected in "_ViewImports" @inject IConfigurationService ConfigurationService And access it each View Page like below: @{ // Configurations var configuration = await ConfigurationService.GetGeneralConfiguration(); var currencySymbol = configuration.Currency.Symbol; } This works, but each page I have to copy and paste the code. I've tried to write the code in _Layout.cshtml but don't works. Static vars also don't works because the values are not

Display EditorFor() value as Read-Only on MVC View?

落花浮王杯 提交于 2020-05-14 19:56:49
问题 I have several fields I display on most of my views in my MVC5 Code-First app: [created_date] , [created_by] , [modified_date] , and [modified_by] . For the user, I would like to include these also on my Edit() view, but unlike my other fields I do not wish to have them editable (commonly created/by and modified/by data should NOT be editable). This is how I have the fields declared on my Edit() view currently: <div class="form-group"> @*@Html.LabelFor(model => model.created_date,

asp.net core tilde slash (~/) not resolving image path

≯℡__Kan透↙ 提交于 2020-05-14 05:55:17
问题 I have some markup in my Index.cshtml view, which has an inline css style with the background-image property. When the page is rendered the correct path of the image is not being generated and the tilde remains in the url HTML Markup: The path that is used on the img tag works properly when the page is rendered, but the path in the background-image property displays like this and the image is not found Rendered Markup: <article class="card-item card-item-colored" style="background-image:url(~

Public variables in MVC 3 Razor _ViewStart

与世无争的帅哥 提交于 2020-05-13 04:32:34
问题 I'm building a site on the new Razor engine that comes with MVC 3 (and loving the new syntax!). However, I am at a loss about using public properties / constants with it. I know that with WebForms we could add a public property in code behind: public string ImageFolder { get; set; } I would like to define important variables in one global place that my views can access, starting with paths to CSS files and images: @{ Layout = "~/Views/Shared/_Layout.cshtml"; var ContentFolder = "~/Content";

Public variables in MVC 3 Razor _ViewStart

妖精的绣舞 提交于 2020-05-13 04:32:09
问题 I'm building a site on the new Razor engine that comes with MVC 3 (and loving the new syntax!). However, I am at a loss about using public properties / constants with it. I know that with WebForms we could add a public property in code behind: public string ImageFolder { get; set; } I would like to define important variables in one global place that my views can access, starting with paths to CSS files and images: @{ Layout = "~/Views/Shared/_Layout.cshtml"; var ContentFolder = "~/Content";

Public variables in MVC 3 Razor _ViewStart

China☆狼群 提交于 2020-05-13 04:31:10
问题 I'm building a site on the new Razor engine that comes with MVC 3 (and loving the new syntax!). However, I am at a loss about using public properties / constants with it. I know that with WebForms we could add a public property in code behind: public string ImageFolder { get; set; } I would like to define important variables in one global place that my views can access, starting with paths to CSS files and images: @{ Layout = "~/Views/Shared/_Layout.cshtml"; var ContentFolder = "~/Content";

Formatting Razor Files in Visual Studio Code

浪尽此生 提交于 2020-05-08 06:17:08
问题 Anyone have a good solution for formatting Razor files inside of VSCode? I've tried making it work with prettify-vscode and beautify. But in both cases it can't tell that cshtml files. I don't want to change my razor to html as I'll lose a lot of the razor-ness. 回答1: You can introduce them as HTML files (File -> Preferences -> Settings) without any 3rd party extensions: { "editor.formatOnSave": true, "emmet.includeLanguages": { "razor": "html" }, "files.associations": { "*.cshtml": "html" } }

MVC Razor, add if statement to foreach loop

…衆ロ難τιáo~ 提交于 2020-05-07 18:25:12
问题 I'm trying to add data from my model to a table with razor. My problem is that i want an if statement to decide what class the tagg should be and i can't get this to work. When i add the if i get the following error when i run the code The foreach block is missing a closing "}" character How should i add the if statement? This is my current code @{ var counter = 0; } @foreach (var item in Model) { if(item.status == "Active") { <tr> } else { <tr class="danger"> } <td>@counter</td> <td>@item