display-templates

How to render ModelMetadata object using Html.Displar in Razor-engine in ASP.NET MVC app?

南笙酒味 提交于 2020-01-23 10:50:47
问题 I am trying to utilize the DisplayTemplates feature in razor-engine to automate rendering my display views. I scan my Model to find the correct ModelMetadata for each property that I want to display. But I am not able to render the properties using Html.DisplayFor correctly. I tried to display my property like so // First I find the ModelMetadata for the property // I call this statement in a loop and each iteration I pass a different PropertyName to get the correct model ModelMetadata

MVC Razor display template

一世执手 提交于 2020-01-01 17:26:45
问题 I have a list of items that I am passing to a view. I would like to render each item using a display template. However, something is wrong, as I don't get the field properly rendered. Here is my main view (Index.cshtml): @model IEnumerable<CustomEntity> @{ ViewBag.Title = "Index"; } @Html.DisplayFor(m=>m) Here is my display template: @model CustomEntity <div> @Html.LabelFor(m=>m.Name): <strong>@Model.Name</strong> @Html.LabelFor(m=>m.Icon): <strong>@Model.Icon</strong> @Html.LabelFor(m=>m

ASP.NET MVC 3 Generic DisplayTemplates

落爺英雄遲暮 提交于 2019-12-19 18:31:38
问题 I've just started a project using ASP.NET MVC 3. I'm building on top of an existing object system, so one of the first things I have to do is define display and editor templates for the various types that exist. Is it possible in MVC to define a DisplayTemplate with a generic argument? For example, we have a BitString<T> class which takes an enumeration as the generic argument and represents a list of options wrapping the supplied enumeration. I'm hoping I can define a single Display/Editor

ASP.NET MVC 3 Generic DisplayTemplates

我的梦境 提交于 2019-12-19 18:31:12
问题 I've just started a project using ASP.NET MVC 3. I'm building on top of an existing object system, so one of the first things I have to do is define display and editor templates for the various types that exist. Is it possible in MVC to define a DisplayTemplate with a generic argument? For example, we have a BitString<T> class which takes an enumeration as the generic argument and represents a list of options wrapping the supplied enumeration. I'm hoping I can define a single Display/Editor

How do I override DisplayFor boolean?

[亡魂溺海] 提交于 2019-12-18 14:12:13
问题 How do i create a display template so i can display a bool as Yes or No not a checkbox? Using mvc3 <%: Html.DisplayFor(model => model.SomeBoolean)%> 回答1: I had to create something similar so it would display "Sim" and "Não" (portuguese Yes/No). I created the following file: Views\Shared\DisplayTemplates\Boolean.ascx And added the following code: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %> <%= (bool) ViewData.Model ? "Sim" : "Não" %> Hope this helps! EDIT

How to use DisplayTemplates in MVC core 2.0

拥有回忆 提交于 2019-12-12 10:53:30
问题 I used to use DisplayTemplates in MVC5 to get rid off foreach loops from views If I have a ProductDto and ProductController I would place a ProductDto.cshtml under Views/Product/DisplayTemplates/ or Views/Shared/DisplayTemplates/ to use the template for list of products: I would replace the foreach loops with the following line to list all products by using the template: @Html.DisplayFor(m=>m.Products); And if I want to use same model ( ProductDto ) in a different display template for

what would I use in this situation(asp.net mvc 3 display templates)

假装没事ソ 提交于 2019-12-11 16:28:05
问题 I have something like this public class ViewModel1 { // some properties here public List<ViewModel2> ViewModel2 {get; set;} } public class ViewModel2 { public string A {get; set;} public string B {get; set;} } // view <table> <thead> <tr> a </tr> <tr> b </tr> </thead> <tbody> // want to use a display template to render table row and cells so I don't need to use for loop </tbody> </table> I tried to use " @Html.DisplayForModel() " but that I seems to take the viewModel of the view(so in my

ASP.NET MVC 3 Razor DisplayFor Delegate

倖福魔咒の 提交于 2019-12-11 01:34:22
问题 I'm getting this error: Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions. Here's my code (custom HTML helper, wrapping DisplayFor so i can choose a template): public static string DisplayLocationTypeFor<TModel>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, LocationType>> expression, bool plural = false) { return plural ? htmlHelper.DisplayFor(expression, "LocationTypePlural").ToHtmlString(

Display template not used for interface

随声附和 提交于 2019-12-10 22:19:21
问题 I'm having a problem with display templates and dealing with interfaces and objects which implement the interface. In the example I have many objects, which I want to be rendered in a fixed way, I decided to create an interface and reference this in the view which I've decided to put into the shared display templates folder. DisplayFor doesn't seam to work for objects passed to it which implement the interface in the view, does any one know a solution to this. Its probably easier to explain

MVC4 Razor DisplayTemplate called, HTML generated, but not rendered to browser

只愿长相守 提交于 2019-12-10 17:54:25
问题 I've got a view that iterates a collection and calls DisplayFor() for each element in the collection. I need to manually iterate (as opposed to passing the collection to DisplayFor) in order to tell the template if a break in the list should be drawn. The items in the list will only be of 2 types, ordered by them, so I only need to show this break once. My template is found and called correctly. I can see the HTML it generates correctly, ie: DisplayFor().ToHtmlString() I can set this HTML as