razor-2

creating multiple dictionary and appending into list using c#

夙愿已清 提交于 2020-06-13 12:27:51
问题 I am new to C# and am trying to create something like this using c#. How we can do that any suggestion. I just want to create list of dict. a = [ { "server": "10.14.13.1", "prefer": "Yes" }, { "server": "10.1.2.1", "prefer": "No" } ] 回答1: public class POCO { [JsonProperty("server")] public string Server { get; set; } [JsonProperty("prefer")] public string Prefer { get; set; } } POCO o1 = new POCO("10.1.2.1", "No"); POCO o2 = new POCO("10.1.2.2", "YES"); List<POCO> list = new List<POCO>() {o1,

creating multiple dictionary and appending into list using c#

▼魔方 西西 提交于 2020-06-13 12:25:49
问题 I am new to C# and am trying to create something like this using c#. How we can do that any suggestion. I just want to create list of dict. a = [ { "server": "10.14.13.1", "prefer": "Yes" }, { "server": "10.1.2.1", "prefer": "No" } ] 回答1: public class POCO { [JsonProperty("server")] public string Server { get; set; } [JsonProperty("prefer")] public string Prefer { get; set; } } POCO o1 = new POCO("10.1.2.1", "No"); POCO o2 = new POCO("10.1.2.2", "YES"); List<POCO> list = new List<POCO>() {o1,

Rendering an email throws a TemplateCompilationException using RazorEngine 3 in a non-MVC project

此生再无相见时 提交于 2020-02-24 12:36:34
问题 I am trying to render emails in a windows service host. I use RazorEngine 3 forked by coxp which has support for Razor 2. https://github.com/coxp/RazorEngine/tree/release-3.0/src This works fine for a couple of emailtemplates but there is one causing me problems. @model string <a href="@Model" target="_blank">Click here</a> to enter a new password for your account. This throws a CompilationException: The name 'WriteAttribute' does not exist in the current context. So passing in a string as

How do I use @Url.Content() in non-MVC Razor webpage?

淺唱寂寞╮ 提交于 2020-01-15 12:14:28
问题 Since I'm using Web Application having NuGet Package's Microsoft.AspNet.Razor installed. In WebForm pages ( .aspx), I can use ResolveUrl() but in Razor pages ( .cshtml), I get this error --> "x:\Source\Foo.Dealer\Foo.Dealer.WebApp.Mobile\Member\DmsDashboard.cshtml(103): error CS0103: The name 'Url' does not exist in the current context" Source-Code here.. @section HeadJavascriptLibraryFile { <script type="text/javascript" src="@Url.Content("~/scripts/webpages/setting-dmsdashboard.js")"><

ASP.NET MVC View not rendering script tags properly

被刻印的时光 ゝ 提交于 2020-01-03 04:33:05
问题 I have a very simple MVC project, and in my _Layout.cshtml I have some js includes like so: <script src="~/scripts/jquery-2.0.3.min.js"></script> <script src="~/scripts/easing.js"></script> <script src="~/scripts/bootstrap.js"></script> However, when it renders, it renders on the page like (note the tilde on the first one): <script src="~/scripts/jquery-2.0.3.min.js"></script> <script src="/scripts/easing.js"></script> <script src="/scripts/bootstrap.js"></script> I can't seem to get it to

MVC4 ViewData.TemplateInfo.HtmlFieldPrefix generates an extra dot

谁都会走 提交于 2020-01-02 02:54:12
问题 I'm trying to get name of input correct so a collection of objects on my view model can get bound. @{ViewData.TemplateInfo.HtmlFieldPrefix = listName;} @Html.EditorFor(m => m, "DoubleTemplate", new { Name = listName, Index = i, Switcher = (YearOfProgram >= i +1) }) As you can see here, I pass in the "listName" as the prefix for my template. the value of listName = "MyItems" And here is my template: @model Web.Models.ListElement @if (ViewData["Switcher"] != null) { var IsVisible = (bool

EditorTemplate Naming Convention for Collection model classes

ε祈祈猫儿з 提交于 2019-12-31 02:58:11
问题 I have a model property that is declared as type List<MyClass> . public class MyModel { List<MyClass> MyProperty { get; set; } } I want to be able to display/edit the property using Razor templates. My question is, how I name an EditorTemplate view so that I can display the property using the normal syntax: @model MyModel @Html.DisplayFor(m => m.MyProperty) I know that I can create a view called MyClass.cshtml that will be used for the type MyClass , but how do I create a template for the

How to add custom data attributes and classes to `@Html.EditorFor`?

佐手、 提交于 2019-12-31 00:45:16
问题 I want to add some custom attributes to the input generated by @Html.EditorFor , I tried the following: @Html.EditorFor(model => model.Percent, new { @class = "percent" }) But it just ignores my class, from what I can tell from searching around is that the template doesn't support adding custom attributes. But how does one create a custom template adding support for the custom attributes, while keeping all the functionality of the old template? 回答1: Please see the following posts, this

Is there a benefit to using @Url.Content(“~”)

放肆的年华 提交于 2019-12-29 07:55:15
问题 I'm new to MVC4/razor2, and I think understand the general benefit of using @Url.Content and @Url.Action - if my routing or virtual directory changes, magic-url-strings are correctly rendered. I'm looking at some legacy Javascript-with-razor code in a view that is peppered with '@Url.Content("~")' . This renders out as '/' - or, website root. Which.... would always be the case, no? Or is there some situation in which this could be rendered differently? Note: it is not ~/ - just plain ol'

How to add a script in a partial view in MVC4?

房东的猫 提交于 2019-12-28 05:35:26
问题 This is the code which I have in my partial view @model Contoso.MvcApplication.Models.Exercises.AbsoluteArithmetic @using(Html.BeginForm()) { <div> <span style="width: 110px; float:left; text-align:center; font-size:2.5em;">@Model.Number1</span> <span style="width: 110px; float:left; text-align:center; font-size:2.5em;">+</span> <span style="width: 110px; float:left; text-align:center; font-size:2.5em;">@Model.Number2</span> <span style="width: 110px; float:left; text-align:center; font-size